Skip to content
This repository has been archived by the owner on Jun 29, 2018. It is now read-only.

Fixed event not triggered correctly. #457

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions wrappers/common/popcorn._MediaElementProto.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand Down Expand Up @@ -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 );
};

Expand Down
7 changes: 6 additions & 1 deletion wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@
function onFirstPause() {
removeYouTubeEvent( "pause", onFirstPause );
if ( player.getCurrentTime() > 0 ) {
player.seekTo( 0 );
player.pauseVideo();
setTimeout( onFirstPause, 0 );
return;
}
Expand All @@ -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 ) {
Expand Down