2015-10-21 187 views
0

我在播放應用程序後臺播放音頻時遇到問題。我打開了目標>功能中的Background Modes,並選中了Audio, Airplay and Picture in Picture & Background fetch模式的複選框。如何讓應用程序背景音頻時繼續播放音頻?

我正在使用核心音頻(不知道這是否有所作爲)。我是否錯過了讓音頻在後臺播放的步驟?音頻播放完全正常時,客戶端是在前臺,但一旦應用程序被轉到後臺,音頻停止

回答

1

確保你也有一個活躍的音頻會話,代碼樣本是從this蘋果技術Q &答:

#import <AVFoundation/AVFoundation.h> 
#import <AudioToolbox/AudioToolbox.h> 

AVAudioSession *audioSession = [AVAudioSession sharedInstance]; 

NSError *setCategoryError = nil; 
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError]; 
if (!success) { /* handle the error condition */ } 

NSError *activationError = nil; 
success = [audioSession setActive:YES error:&activationError]; 
if (!success) { /* handle the error condition */ } 
相關問題