However, when I leave the page, the media keeps playing, and I notice in XCode that the memory usage remains high - so I assume the object is not being stopped and destroyed as I want.
I have also specified ‘cache: false’ in the main state setup:
Hey @Mik378 - Thanks for your quick reply. I just tried using $ionicView.leave, beforeLeave and afterLeave, but it still does not seem to fire. I placed a console.log() message in the function just in case the media was being cached separately, but not getting the message in the console, so I suspect that the event is just not being triggered somehow… ??
Seen a few other threads on here with people reporting a problem with $ionicView.xxx so not sure if it is a bug in the current beta?
I think $ionicView.beforeLeave and $ionicView.afterLeave are not called when the user chooses another tab. In the codepen @mhartington just posted, I only get the alert when changing views within the home tab, not when switching away from the home tab.
My app uses the ‘sidemenu’ starter template. I have a side menu which call a view with a list, then tapping on a list item calls the subsequent player view which is where I am having the problem. Not sure if the order of the routing is a factor here. When I go ‘Back’ from the player view to the list again, or use the sidemenu to choose another section of the app, the events don’t seem to fire?
Get on the home tab and make the sure the Youtube video player is playing and not muted.
Click on “Scientific Facts”.
The video should get removed from the DOM but doesn’t.
It finally does when the user navigates back to the page.
Note the ‘)’ after ‘$ionicView.beforeLeave’ and the missing ‘)’ at the end. Ionic accepted this as a valid block even with this syntax error, and the call was never being triggered! Moving the closing bracket to the proper spot fixed this.
“I only get the alert when changing views within the home tab, not when switching away from the home tab.”
In my case also, the beforeLeave event isn’t triggered when I click directly on another tab.
However, the enter event is well triggered.
Sounds like a real bug.
Apologies - I meant that the issue was solved in MY situation. I am using a SideMenu based app, and it works within that context. Haven’t test in a Tab based app, but I take your word that it is broken there, as other have mentioned it as well. Hopefully will be fixed up by Ionic soon…