Search code examples
ipadcordovampmovieplayercontrollerhybrid-mobile-app

In hybrid application, HTML player and Native player are getting inter-connected, why?


We are developing hybrid application (Phonegap + Native). It has 3-tabs where 1st tab loads Phonegap HTML contents and the other two tabs are loading entire native-based contents.

In both (HTML + Native) tabs there is an option to play a video, here is a complete scenario:

  • Play video file for some time in Online tab - pause video
  • Shift to offline tab - play video file for some time - pause video
  • Go back to Online tab - it display the paused video page (as default tab behaviour) - now play video here
  • Doing this will automatically starts offline tab video as well, whereas we have condition in viewWillDisappear - if video is playing then pause it. And it is getting called and getting paused as well.

But somehow, while playing video in online tab also have reference to offline tab, and plays offline video as well.

How can it be possible? Please suggest.


Solution

  • Short answer:

    That "inter-connection" happens because PhoneGap is using the same video instance for both tabs.

    A bit more indeep:

    You're obviously not disconnecting the videos by unloading... since you are pausing the video instances, not stopping and unloading them. A workaround would be to store the playback position and actually stop the video when switching between offline and online tab.

    In simpler words: don't keep a video paused when the tab becomes inactive since it not only hogs resources for something the user doesn't see anyway, but you're also keeping the video linked. Phonegap itself doesn't differ what tab is playing the same video, so you'll need to handle it yourself via code. If you don't, Phonegap will do what you are currently noticing: it'll "unpause" all linked videos that identify as "the same video" (no matter what tab).