AVPlayer流媒体音频在后台

Pat*_*ote 10 background audio-streaming ios avplayer

AVPlayer在后台模式下播放时遇到问题,就像网络上的很多人一样.我已经完成了我认为应该工作的东西,但仍然没有...我认为我的问题可能是我设置和使用我的AudioSession和AVPlayer的地方.

1)"audio"键位于我的Info.plist的UIBackgroundModes中

2)AudioSession在AppDelegate中设置如下(在didFinishLaunchingWithOptions中初始化):

AVAudioSession *audio = [[AVAudioSession alloc]init];
[audio setCategory:AVAudioSessionCategoryPlayback error:nil];
[audio setActive:YES error:nil];
Run Code Online (Sandbox Code Playgroud)

3)我使用了也在AppDelegate中实现的AVPlayer(不是AVAudioPlayer).(在AudioSession之后的didFinishLaunchingWithOptions中初始化),紧跟在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];
Run Code Online (Sandbox Code Playgroud)

而且,每当应用程序进入后台时(当我按下"主页"按钮时),音频就会暂停.

Pat*_*ote 5

顺便说一下,问题只在于模拟器.适用于iOS设备