[英]How to play a sound file at maximum volume in iOS without a sound indicator change
在我的应用程序中,我需要播放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;
然后安排一个计时器来增加音量
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(pollTimeForGradualVolumeIncrease)
userInfo:nil repeats:YES];
//逐渐增加音量
- (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;
}
}
问题是在设置MPMusicPlayerController.applicationMusicPlayer.volume
时,iOS音量指示器将出现
有没有办法在不显示iOS音量已更改指示的情况下以最大设备音量播放声音文件的方法?
我在8个月前就在尝试相关的事情,据我所记得,如果存在MPVolumeView,则iOS不会显示系统音量已更改的指示器。
如果您实际上不想看到MPVolumeView,我想您可以将其隐藏在另一个视图后面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.