开发者

AVPlayer streaming audio in background

开发者 https://www.devze.com 2023-02-14 10:24 出处:网络
I have a problem with the AVPlayer playing in background mode, like a lot of people here and everywhere on the web. I\'ve done what I think is supposed to work, but is still doesn\'t... I think my pro

I have a problem with the AVPlayer playing in background mode, like a lot of people here and everywhere on the web. I've done what I think is supposed to work, but is still doesn't... I think my problem might be where I set and use my AudioSession and AVPlayer.

1) The "audio" key is in UIBac开发者_StackOverflow社区kgroundModes of my Info.plist

2) AudioSession set like this in AppDelegate (initialised in didFinishLaunchingWithOptions):

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

3) I use an AVPlayer (not AVAudioPlayer) also implemented in AppDelegate. (initialised in didFinishLaunchingWithOptions, after the AudioSession), right after the 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];

And still, the audio is suspended everytime the app goes in background (when I press the "Home" button).


By the way, the problem was just with the simulator. Works fine on the iOS devices

0

精彩评论

暂无评论...
验证码 换一张
取 消