我正在嘗試AVFoundationFramework
。當應用程序轉到後臺時,AVAudioPlayer不播放
目前我能夠在前臺運行AVAudioPlayer
。 當應用程序轉到後臺時,AVAudioPlayer
不會繼續播放。
實施的具體步驟是:
添加後臺任務給的.plist
設置
AVAudioPlayer
self.objAVAudioPlayer = [[AVAudioPlayer alloc]initWithData:mp3Data error:&error]; self.objAVAudioPlayer.delegate = self;
設置
AVAudioSession
if([self.objAVAudioPlayer prepareToPlay]) { AVAudioSession *objAVAudioSession = [AVAudioSession sharedInstance]; [objAVAudioSession setCategory:AVAudioSessionCategoryPlayback error:&error]; [objAVAudioSession setActive:YES error:nil]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; [self.objAVAudioPlayer play]; }
當應用程序恢復,它從那裏辭職完全一樣的地方開始。
基本SDK是iOS 7.0
。
任何想法我缺少什麼?任何幫助將不勝感激。
你在你的'有什麼添加以下代碼
到您
AppDelegate.m
類 - (空)applicationDidEnterBackground :(UIApplication *)應用程序? – Aluminum尚未在'applicationDidEnterBackground'中實施任何代碼 – footyapps27
您是否使用您的應用ID啓用了應用內音頻權利? – ZeMoon