I have an issue where when user is playing a video , while video is being player, he uses siri to search for a different movie, which will load its corresponding movie details page and then select to play that movie, which deeplinks to your app which is playing a movie, when i play a new selected movie and dismiss avplayer and avplayercontroller, audio from previous video still continues to play. somehow avplayer is not cleared although i clear all subviews from window and initialize its super view controller class again. I am cluless what can i do erase older instance of avplayer. Let me know if anyone has any suggestions or faced similar issue.
1 Answer
A few suggestions:
- Are you subclassing
AVPlayerViewController
? If so, that's a bad idea. The API docs specifically say not to do that. - Add a
deinit
function. If it's not being called when the oldAVPlayer
is dismissed, you know you have a retention problem. This is often caused by registering for notifications or boundary time observers. - If you view controller has a reference to the
AVPlayer
object, you might try overriding theviewDidDisappear
function to call player.pause() and then setting the player reference first to a new instance ofAVPlayer()
then tonil
. Not sure why this helps, but sometimes it does.
Definitely implement #2 above. If deinit is not getting called, you most certainly have an issue.