私のアプリでは、音量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;
}
}
これに伴う問題は、設定時にiOSの音量インジケーターが表示されることですMPMusicPlayerController.applicationMusicPlayer.volume
iOSの音量変更インジケーターを表示せずに最大デバイス音量でサウンドファイルを再生する方法はありますか?