Iphone AVPlayer背景问题
我的Iphone AVPlayer背景问题,iphone,ios,background,avplayer,Iphone,Ios,Background,Avplayer,我的AVPlayer有一个问题,当我试图让播放器在后台工作时,iphone6.0模拟器工作正常,但当应用程序进入后台时,真实设备上的声音消失了 - (IBAction)RayaFM { NSURL *URLA = [NSURL URLWithString:@"http://live.raya.fm:8032/;stream.mp3"]; self.player = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWi
AVPlayer
有一个问题,当我试图让播放器在后台工作时,iphone6.0模拟器工作正常,但当应用程序进入后台时,真实设备上的声音消失了
- (IBAction)RayaFM {
NSURL *URLA = [NSURL URLWithString:@"http://live.raya.fm:8032/;stream.mp3"];
self.player = [AVPlayer playerWithPlayerItem:[AVPlayerItem playerItemWithURL:URLA]];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
UIBackgroundTaskIdentifier newTaskId = UIBackgroundTaskInvalid;
[self.player play];
newTaskId = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:NULL];
if (newTaskId != bgTaskId != UIBackgroundTaskInvalid)
[[UIApplication sharedApplication] endBackgroundTask: bgTaskId];
bgTaskId = newTaskId;
}
您还需要在-info.plist文件中包含以下内容:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
ui背景模式
您还需要在-info.plist文件中包含以下内容:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
ui背景模式