只要我的應用程序正在運行,我需要始終播放背景音。我試圖使用AVAudioPlayer來達到這個目的。但是,只要iPhone進入睡眠模式,它就會停止播放聲音。當iPhone進入睡眠狀態時,AVAudioPlayer會停止播放音頻
你能告訴我如何解決這個問題嗎?
謝謝
只要我的應用程序正在運行,我需要始終播放背景音。我試圖使用AVAudioPlayer來達到這個目的。但是,只要iPhone進入睡眠模式,它就會停止播放聲音。當iPhone進入睡眠狀態時,AVAudioPlayer會停止播放音頻
你能告訴我如何解決這個問題嗎?
謝謝
您可能需要設置音頻會話類別。從「iPhone應用程序編程指南」
類別是識別您 應用 組音頻行爲的關鍵。通過設置一個類別, 表示您的音頻意圖爲 iPhone OS,例如您的音頻 應該在屏幕鎖定時繼續。
瞭解各個類別的細節在「Audio Session Categories」
謝謝。有用。 – ebaccount 2009-05-26 18:06:10
列在您具體的例子,你可以嘗試以下。它應該可以直接使用。
// 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];
以及該溶液也可以是有益的
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
從 http://www.mindyourcode.com/ios/iphone/how-to-play-audio-in-iphone-sleep-mode/
http://stackoverflow.com/questions/908469/playing-a-sound-using-的杜佩引用ipod-application – ceejayoz 2009-05-26 03:00:42