Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS AVPlayer cancel buffering

If I load an AVPlayer with a file from a host with

[AVPlayer playerWithPlayerItem:playerItem];

And the "buffering" takes longer than the user wants, how do I allow them to cancel it?

like image 234
justdan0227 Avatar asked Oct 01 '15 16:10

justdan0227


4 Answers

So the correct answer is @Che with:

If you will call [self.player replaceCurrentItemWithPlayerItem:nil]; buffering stops. – Che Oct 13 at 14:36

and you do so on the observer listening for the status update from the playerWithPlayerItem. Thanks All!

like image 118
justdan0227 Avatar answered Oct 13 '22 17:10

justdan0227


you can try this

// pause buffer
[self.playerItem cancelPendingSeeks];
[self.playerItem.asset cancelLoading];
like image 30
user7301096 Avatar answered Oct 13 '22 19:10

user7301096


I don't think there is a method to directly stop buffering. But you can check the boolean playbackLikelyToKeepUp property of the AVPlayerItem to check if the buffer is loading. I not then pause playback on the AVPlayer.

like image 23
Ishan Handa Avatar answered Oct 13 '22 17:10

Ishan Handa


Swift 3

player?.replaceCurrentItem(with: nil)
like image 38
Sébastien REMY Avatar answered Oct 13 '22 19:10

Sébastien REMY