jeudi 30 juin 2016

How to change url of AVAsset on next page and come to the previous page without having memory issues iOS

I am building an app and the scenario is something like this:

I have 3 view controllers VC1,VC2,VC3.

scenario1 I have an AVPlayer on VC2 that uses a "NSURL" saved in userDefaults to play a video.Let us say that the key to this url is "videoURL".Now if I pop VC2 and go back to VC1,dealloc() gets called and everything gets deallocated and the video stops playing.So,if I change the "videoURL" on VC1 and then push VC2 onto the navigation stack,I get a new AVPlayer with the previous one being deallocated.No problems till now.

scenario2 If I change "videoURL" on VC2,I get a new playerItem using "replaceCurrentItemWithPlayerItem" to play a new video.No problems here as well.

scenario3 Now if I push VC3 onto the stack,I don't know how to play a new URL if I pop back to VC3.The video doesn't stop playing when I push VC3,even if I set AVPlayer to nil before pushing VC3.And when I do stop the video and push VC3,I am facing memory issues.

What is the correct way to implement scenario3?

Aucun commentaire:

Enregistrer un commentaire