另一个AVPlayer在后台播放流式音频问题
问题描述:
我在背景模式下播放AVPlayer时遇到了问题,就像很多人在网络上的任何地方一样。我已经完成了我认为应该工作的内容,但仍然没有......我认为我的问题可能是我设置和使用AudiSession和AVPlayer的地方。另一个AVPlayer在后台播放流式音频问题
1) “音频” 键是在我的Info.plist的UIBackgroundModes
2)AudioSession在AppDelegate中设置像这样(在didFinishLaunchingWithOptions初始化):
AVAudioSession *audio = [[AVAudioSession alloc]init];
[audio setCategory:AVAudioSessionCategoryPlayback error:nil];
[audio setActive:YES error:nil];
3)I使用AVPlayer (而不是AVAudioPlayer)也在AppDelegate中实现。 (初始化在didFinishLaunchingWithOptions中,AudioSession后),AudioSession之后
// Load the array with the sample file
NSString *urlAddress = @"http://mystreamadress.mp3";
//Create a URL object.
self.urlStream = [NSURL URLWithString:urlAddress];
self.player = [AVPlayer playerWithURL:urlStream];
//Starts playback
[player play];
而且还在,音频每次暂停该应用程序进入后台(当我按下“主页”按钮)...谁能帮助我请这个好吗?
答
顺便说一下,问题只是模拟器。在iOS设备上正常工作