[英]how to handle the interruption in iphone
當我的ipod處於鎖定(睡眠)狀態時,我的iPhone上的AVAudioPlayer出現問題,歌曲停止了。即使在ipod處於鎖定(睡眠狀態)的情況下,我在編碼音樂方面所做的工作仍在繼續。 請幫我
我對此完全陌生。
您可以使用不同的類別來執行此操作:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
...
// allows you to play when the screen is locked and also when the ringer is set to silent
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];
...
}
如果您想在應用暫停到后台(例如,用戶按下主屏幕按鈕)時繼續在iOS4上播放聲音,則還需要將其添加到info.plist
文件中(以純文本形式顯示)文字模式):
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
順便說一句,如果您真的需要處理您的問題標題(例如電話等)這樣的中斷,則AVAudioPlayer
類中有一個委托方法:
- (void) audioPlayerBeginInterruption: (AVAudioPlayer *) player { }
和
- (void) audioPlayerEndInterruption: (AVAudioPlayer *) player { }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.