2009-05-25 96 views
4

只要我的應用程序正在運行,我需要始終播放背景音。我試圖使用AVAudioPlayer來達到這個目的。但是,只要iPhone進入睡眠模式,它就會停止播放聲音。當iPhone進入睡眠狀態時,AVAudioPlayer會停止播放音頻

你能告訴我如何解決這個問題嗎?

謝謝

+0

http://stackoverflow.com/questions/908469/playing-a-sound-using-的杜佩引用ipod-application – ceejayoz 2009-05-26 03:00:42

回答

5

您可能需要設置音頻會話類別。從「iPhone應用程序編程指南」

類別是識別您 應用 組音頻行爲的關鍵。通過設置一個類別, 表示您的音頻意圖爲 iPhone OS,例如您的音頻 應該在屏幕鎖定時繼續。

瞭解各個類別的細節在「Audio Session Categories

+0

謝謝。有用。 – ebaccount 2009-05-26 18:06:10

4

列在您具體的例子,你可以嘗試以下。它應該可以直接使用。

// Registers this class as the delegate of the audio session. 
[[AVAudioSession sharedInstance] setDelegate: self];  
// Allow the app sound to continue to play when the screen is locked. 
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil]; 
相關問題