0
我需要在iOS中製作一個應用程序,在其功能期間發出不同的聲音,如「嘟嘟」。在我的應用程序中減少/減少背景音頻
我用MPMusicPlayerController實現了與後臺ipod的交互。
的probleme:
我沒有聽到「嘟」由於音樂從iPod的音量。 我需要減少iPod的音量,但不能減少我的應用程序的音量。 tomtom應用程序使得當演講者提供關於要採取的方向的信息。但是我不知道怎麼做。
我試試這個代碼:
- (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];
}
但「setVolume」降低了設備的所有聲音的音量,包括我的應用程序的聲音......
我需要你的幫助。
謝謝。
十分感謝了很多,它的作品! – Lumi