Why doesn't AVPlayer stop loading data?
Question
When I watch my mac's network connectivity I can tell that a movie is still buffering even after I remove the view which had the AVPlayer on it.
Does anyone know how to force AVPlayer to stop loading data?
Solution 4
I figured it out.
When you want to stop an AVPlayerItem from loading, use AVQueuePlayer's removeAllItems and then re-initialize it.
[self.avPlayer removeAllItems];
self.avPlayer = [AVQueuePlayer playerWithURL:[NSURL URLWithString:@""]];
self.avPlayer = nil;
This will stop the current item from loading -- it is the only way I found to accomplish this.
OTHER TIPS
Maybe it's late to answer this question, but I've just solved the same one. Just save here in case anyone need...
[self.player.currentItem cancelPendingSeeks];
[self.player.currentItem.asset cancelLoading];
There's no cancel method in AVPlayer
class, but in AVPlayerItem
and AVAsset
class, there are!
PS: player
here is AVPlayer
class, not AVQueuePlayer
class.
I had the same issue and this line solved it..
self.avPlayer?.replaceCurrentItem(with: AVPlayerItem(url: URL.init(string: "https://www.asdfasdfasdfasdfasdfasd.net/")!))
I also call the function
asset?.cancelLoading()
where asset is my AVURLAsset
object inside my player handler class
An AVPlayer is not a view. You may have "removed the view" but that does not mean you have removed or stopped the AVPlayer. I would guess that the way to do what you want is to destroy the AVPlayer itself.