diff --git a/wrappers/common/popcorn._MediaElementProto.js b/wrappers/common/popcorn._MediaElementProto.js index e52c09670..90934ce65 100644 --- a/wrappers/common/popcorn._MediaElementProto.js +++ b/wrappers/common/popcorn._MediaElementProto.js @@ -69,6 +69,18 @@ return MediaError; }()); + // Make sure the browser has CustomEvent + window.CustomEvent = window.customEvent || (function () { + function CustomEvent ( event, params ) { + params = params || { bubbles: false, cancelable: false, detail: {}}; + var evt = document.createEvent( 'CustomEvent' ); + evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail ); + return evt; + }; + + CustomEvent.prototype = window.Event.prototype; + return CustomEvent; + }()); function MediaElementProto() { var protoElement = {}, @@ -110,14 +122,16 @@ }; protoElement.dispatchEvent = function( name ) { - var customEvent = document.createEvent( "CustomEvent" ), - detail = { + var customEvent = new CustomEvent(this._eventNamespace + name, { + detail: { type: name, target: this.parentNode, data: null - }; + }, + bubbles: true, + cancelable: false + }); - customEvent.initCustomEvent( this._eventNamespace + name, false, false, detail ); document.dispatchEvent( customEvent ); }; diff --git a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js index 4aeadba39..e53a6132d 100644 --- a/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js +++ b/wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js @@ -220,6 +220,8 @@ function onFirstPause() { removeYouTubeEvent( "pause", onFirstPause ); if ( player.getCurrentTime() > 0 ) { + player.seekTo( 0 ); + player.pauseVideo(); setTimeout( onFirstPause, 0 ); return; } @@ -236,12 +238,15 @@ function onFirstPlay() { removeYouTubeEvent( "play", onFirstPlay ); if ( player.getCurrentTime() === 0 ) { + player.playVideo(); setTimeout( onFirstPlay, 0 ); return; } addYouTubeEvent( "pause", onFirstPause ); player.seekTo( 0 ); - player.pauseVideo(); + setTimeout(function() { + player.pauseVideo(); + }, 500); } function addYouTubeEvent( event, listener ) {