首页 文章

AVPlayer流媒体音频在后台

提问于
浏览
10

我有一个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];

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];

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

1 回答

  • 5

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

相关问题