[英]AVPlayer streaming audio in background
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];
而且,每當應用程序進入后台時(當我按下“主頁”按鈕時),音頻就會暫停。
順便說一下,問題只在於模擬器。 適用於iOS設備
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.