0
votes

I am playing Music from Url using AVPlayer and clicking on the play button will take some time to play because of buffering. There are two cases that i have explained below.

Success case: I am clicking on the play button and the AVPlayer buffers and starts playing. After the player have started playing i am pressing the home button and the application goes to the background and the playing continues.

Failure case: I am clicking on the play button and the AVPlayer starts buffering. I will press the home button and the application goes to the background while the AVPlayer is buffering and before its starts playing. AVPlayer doesn't play in the background even though play command is already issued.

and suggestions?

Thanks in advance,

Norbert

1
At what point are you activating the AudioSession? AudioSessionSetActive(true);SteveB
- (void)applicationWillEnterForeground:(UIApplication *)application { if(![avplayer isPlaying]) { //post notification which will call method to play sound}}Paresh Navadiya

1 Answers

2
votes

if the buffering takes more than 2 seconds, the task will be frozen before playback starts.

use

task = [application beginBackgroundTaskWithExpirationHandler:...

the second problem is that AVPlayer's status fails if trying to start playing in the background if you don't acquire the remote controls.

[application beginReceivingRemoteControlEvents];

One of those should fix the issue.