我遇到AVPlayer
的问题,当我尝试让播放器在后台运行时,iPhone 6.0模拟器工作正常,但当应用程序进入后台时,真实设备上的声音消失了!< / p>
- (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;
}
答案 0 :(得分:3)
您还需要在-info.plist文件中包含以下内容:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
请参阅http://developer.apple.com/library/ios/#qa/qa1668/_index.html