如何在iOS中以最大音量播放声音文件而不改变声音指示器

gab*_*oze 8 iphone audio volume max ios

在我的应用程序中,我需要播放从0到最大系统音量的声音(这是一个警报应用程序).

我目前AVAudioPlayer用来播放声音并MPMusicPlayerController在闹钟期间最大化设备的音量

MPMusicPlayerController.applicationMusicPlayer.volume = 1.0;


NSString *fileName = [NSString stringWithFormat:alarm.sound];
fileName = [fileName stringByDeletingPathExtension];

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"aifc"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
audioPlayer.volume = 0.0;
audioPlayer.numberOfLoops = -1;

[audioPlayer prepareToPlay];

audioPlayer.play;
Run Code Online (Sandbox Code Playgroud)

然后我安排一个计时器来增加音量

timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                         target:self
                                       selector:@selector(pollTimeForGradualVolumeIncrease)
                                       userInfo:nil repeats:YES];
Run Code Online (Sandbox Code Playgroud)

//逐渐增加音量

- (void)pollTimeForGradualVolumeIncrease
{
    timerSecond += 1;

    if (audioPlayer.volume < 1.0 && timerSecond % 1 == 0)
    {
        [audioPlayer setVolume:audioPlayer.volume + 0.02];
        UISlider *slider = volumeSliderView.subviews[0];
        [slider setValue:1.0 animated:NO];
    }
    else if (audioPlayer.volume >= 1.0)
    {
        timerSecond = 0;
        timer.invalidate;
        timer = nil;
    }
}
Run Code Online (Sandbox Code Playgroud)

这个问题是设置时会出现iOS音量指示器 MPMusicPlayerController.applicationMusicPlayer.volume

有没有办法以最大设备音量播放声音文件而不显示iOS音量变化指示器?

Ash*_*ley 3

8个月前我正在尝试相关的事情,据我所知,如果存在 MPVolumeView,iOS 就不会显示系统音量更改指示器。

如果您实际上不想看到 MPVolumeView,我想您可以将其隐藏在另一个视图后面。