Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to properly delete/release AVPlayer/AVPlayerItem?

I am implementing a video app, that lists video and able to stream or watch local videos. If I try to watch videos with my player that inherits from AVPlayer, a lot of threads initated, after 15-20 times, the system does not alloc the AVPlayer well and, even if I do not get any error, the player view is blank and nothing happening...I need to kill app to restore.

How to deal with it?

Thanks in advance

like image 995
erdemgc Avatar asked Oct 07 '15 17:10

erdemgc


People also ask

What is an avplayeritem?

An object that models the timing and presentation state of an asset that a player object presents. An AVPlayerItem stores a reference to an AVAsset object, which represents the media to be played.

What is avasset and avplayer?

AVPlayer — An AVPlayer is a controller object used to manage the playback and timing of a media asset. You can use an AVPlayer to play local and remote file-based media, such as QuickTime movies and MP3 audio files, as well as audiovisual media served using HTTP Live Streaming. Line 1 — AVAsset object is created using the video URL.

What is Ava and avplayeritem in Java?

A class that encapsulates the presentation state of an AVAsset being played by a AVPlayer object. The AVPlayerItem holds the dynamic presentation state of an AVAsset being played by a AVPlayer. Creates a new T:AVFoundation.AVAVPlayerItem suitable for playing asset.

How to automatically load asset keys in avplayeritem?

Alternatively, AVPlayerItem can automatically load the needed asset data for you by passing the desired set of keys to its init (asset:automaticallyLoadedAssetKeys:) initializer. When the player item is ready to play, those asset properties will have been loaded and are ready for use. AVPlayerItem is a dynamic object.


1 Answers

I had the same issue, in my case the AVPlayerLayer didn’t get DE allocated successfully because somehow a custom label grabbed the strong reference of controller and the controller did not get DE allocated. 

Implement


deinit {

}



in your controller and check this called or not. If not you have the solution. 
I hope this helps.

like image 134
Nouman Avatar answered Sep 19 '22 21:09

Nouman