Ios 减少/减少我的应用程序中的ipod背景声音
我需要在iOS中制作一个应用程序,在她的爱抚过程中发出不同的“嘟嘟”声 我已经用MPMusicLayerController实现了与后台ipod的交互 问题是: 由于ipod的音乐音量太大,我听不到“嘟嘟”声。 我需要减小ipod的音量,但不能减小应用程序的音量。 tomtom应用程序会在演讲者提供有关方向的信息时执行此操作。但我不知道怎么做 我尝试了以下代码:Ios 减少/减少我的应用程序中的ipod背景声音,ios,audio,Ios,Audio,我需要在iOS中制作一个应用程序,在她的爱抚过程中发出不同的“嘟嘟”声 我已经用MPMusicLayerController实现了与后台ipod的交互 问题是: 由于ipod的音乐音量太大,我听不到“嘟嘟”声。 我需要减小ipod的音量,但不能减小应用程序的音量。 tomtom应用程序会在演讲者提供有关方向的信息时执行此操作。但我不知道怎么做 我尝试了以下代码: - (void)playSoundCountDown{ NSError *errorObject = nil; [[AVAudioS
- (void)playSoundCountDown{
NSError *errorObject = nil;
[[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryAmbient error:&errorObject];
if (errorObject) {
NSLog(@"Error setting category! %@",errorObject);
}
NSString *path = [[NSBundle mainBundle] pathForResource:@"countDownFiveToOne" ofType:@"caf"];
theSound = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
theSound.delegate = self;// (AVAudioPlayer *theSound;)
[theSound setVolume:0.4f];
[theSound play];
float volumeDecrease = 0.2f;
MPMusicPlayerController* iPodMusicPlayer = [MPMusicPlayerController iPodMusicPlayer];
[iPodMusicPlayer setVolume:volumeDecrease];
}
但是“设置音量”会降低设备所有声音的音量,包括我的应用程序的声音
我需要你的帮助
谢谢。不要降低音量,而是尝试启用回避:
- (void)playSoundCountDown{
NSError *errorObject = nil;
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryAmbient
withOptions: AVAudioSessionCategoryOptionDuckOthers
error: nil];
NSString *path = [[NSBundle mainBundle] pathForResource:@"countDownFiveToOne" ofType:@"caf"];
theSound = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil];
theSound.delegate = self;
[theSound setVolume:0.4f];
[theSound play];
}