iphone开发如何后台播放音频

<!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->


1、在程序播放音频前,添加下面代码

NSError *myErr = nil;

AVAudioSession *audioSession = [AVAudioSession sharedInstance];

BOOL bAudioInputAvailable = [audioSession inputIsAvailable];

 

if (bAudioInputAvailable)

   [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&myErr];

}    

else

{

   [audioSession setCategory:AVAudioSessionCategoryPlayback error:&myErr];

}


2、在info.plist文件中添加Requried background modes,属性值为App plays audio



你可能感兴趣的:(iPhone开发)