GoodSp33d
GoodSp33d

Reputation: 6282

Phonegap InAppBrowser doesnt stop YouTube video on closing

Am using InAppBrowser to play YouTube videos. Am able to embed videos and play it, but while its playing if I click on "Done" button it goes back to where it was, but still I can hear the audio. It looks like it didnt kill the childBrowser. I tried clearing out the player HTML in order to stop the video, but even that didnt work.

var childBrowser = window.open(videoUrl, '_blank', 'location=yes');
// childBrowser is an InAppBrowser object
childBrowser.addEventListener('exit', function(event) {
        top.document.getElemenetById("player").innerHTML = "<p></p>";
});

Any solution ?

Upvotes: 0

Views: 763

Answers (1)

sikac
sikac

Reputation: 56

I had similar problems and, adapted to your code, the solution would look like this:

 var childBrowser = window.open(videoUrl, '_blank', 'location=yes');

 var closeCB = function(event){
  childBrowser.removeEventListener('exit',closeCB);
  childBrowser.close();
  childBrowser = null;

  //for reusability purposes I strongly suggest that you use "display: none" here
  top.document.getElemenetById("player").style.display = "none";
};

childBrowser.addEventListener('exit', closeCB);

Upvotes: 1

Related Questions