【问题标题】:AVPlayer streaming audio in backgroundAVPlayer 在后台流式传输音频
【发布时间】:2011-07-06 23:27:26
【问题描述】:

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

1)“音频”键在我的 Info.plist 的 UIBackgroundModes 中

2) 在 AppDelegate 中这样设置 AudioSession(在 didFinishLaunchingWithOptions 中初始化):

AVAudioSession *audio = [[AVAudioSession alloc]init];
[audio setCategory:AVAudioSessionCategoryPlayback error:nil];
[audio setActive:YES error:nil];

3) 我使用同样在 AppDelegate 中实现的 AVPlayer(不是 AVAudioPlayer)。 (在 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 background audio-streaming avplayer


    【解决方案1】:

    顺便说一句,问题出在模拟器上。在 iOS 设备上运行良好

    【讨论】:

      猜你喜欢
      • 2012-01-18
      • 2012-10-19
      • 2016-01-05
      • 1970-01-01
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多