2011-06-23 133 views
7

我正在尋找一種方法來恢復我的應用程序使用AVAudioPlayer播放自己的聲音後由另一個應用播放的音頻。現在,如果我正在聽音樂並啓動我的應用程序,它會暫停音樂,播放我的聲音,但不會恢復背景音樂。使用AVAudioPlayer播放聲音後恢復背景音頻

下面是我在做什麼,產生的聲音回放:

myChime = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"chime" ofType:@"mp3"]] error:nil]; 
myChime.delegate = self; 
[myChime play]; 
// Here I am looking to resume the audio that the system was playing before my application played its sound. I have seen many applications do this such as, GPS apps that speak a voice direction and then resume the music. 
+0

許多應用程序(如MotionX-GPS)將允許iPod播放背景音樂,直到出現配音,然後暫停音樂,播放「左轉」聲音並恢復iPod播放。我想知道一旦我的聲音完成播放後如何恢復以前的系統音頻播放。 – wasabi

+0

我也面臨這個問題。你能否在這裏提供任何示例代碼?提前致謝。 – Gopinath

+0

你能幫我解決這個問題嗎?我花了兩天時間呢?等待你的回覆。請參閱我的問題以供參考:http://stackoverflow.com/questions/12475034/how-to-stop-and-resume-background-audio-from-iphone-app – Gopinath

回答

7

您需要正確實施AVAudioSession委託方法。如果您將音頻會話設置爲不活動,則系統會知道您已完成播放聲音並將恢復其他任何音頻會話。參考Audio Session Programming Guide,特別是setActive:error:方法。

+0

我也在同樣的問題中掙扎。我正在使用AVAudioPlayer播放我的應用程序音頻並使用AVAudioSession * audioSession = [AVAudioSession sharedInstance]; [audioSession setActive:NO er​​ror:nil]; [audoPlayerObj播放]; [audioSession setActive:YES error:nil] ;.仍然其他應用程序音頻沒有恢復後,音頻palyed形成我的應用程序。 – Gopinath

+0

你能幫我解決這個問題嗎?我花了兩天時間呢?等待你的回覆。請參閱我的問題以供參考:http://stackoverflow.com/questions/12475034/how-to-stop-and-resume-background-audio-from-iphone-app – Gopinath

+0

對不起,我不是一個常客。我傾向於遠離幾天。讓我看看這個並回復你。 – rage