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

[#961778] Get YouTube passing all tests again. #372

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
64 changes: 29 additions & 35 deletions wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,17 @@
}

function onReady() {

addYouTubeEvent( "play", onPlay );
addYouTubeEvent( "pause", onPause );
// Set initial paused state
if( impl.autoplay || !impl.paused ) {
removeYouTubeEvent( "play", onReady );
impl.paused = false;
addMediaReadyCallback(function() {
onPlay();
if ( !impl.paused ) {
onPlay();
}
});
}

Expand All @@ -197,12 +203,12 @@
self.dispatchEvent( "canplay" );

mediaReady = true;
bufferedInterval = setInterval( monitorBuffered, 50 );

while( mediaReadyCallbacks.length ) {
mediaReadyCallbacks[ 0 ]();
mediaReadyCallbacks.shift();
}
bufferedInterval = setInterval( monitorBuffered, 50 );

// We can't easily determine canplaythrough, but will send anyway.
impl.readyState = self.HAVE_ENOUGH_DATA;
Expand All @@ -214,11 +220,14 @@
setTimeout( onFirstPause, 0 );
return;
}
addYouTubeEvent( "play", onPlay );
addYouTubeEvent( "pause", onPause );
removeYouTubeEvent( "pause", onFirstPause );

onReady();
if( impl.autoplay || !impl.paused ) {
addYouTubeEvent( "play", onReady );
player.playVideo();
} else {
onReady();
}
}

// This function needs duration and first play to be ready.
Expand Down Expand Up @@ -268,7 +277,11 @@

// paused
case YT.PlayerState.PAUSED:
dispatchYouTubeEvent( "pause" );
// Youtube fires a paused event before an ended event.
// We have no need for this.
if ( player.getDuration() !== player.getCurrentTime() ) {
dispatchYouTubeEvent( "pause" );
}
break;

// buffering
Expand Down Expand Up @@ -477,15 +490,13 @@
}

function onPlay() {

if( impl.ended ) {
changeCurrentTime( 0 );
impl.ended = false;
}
timeUpdateInterval = setInterval( onTimeUpdate,
self._util.TIMEUPDATE_MS );
impl.paused = false;

if( playerPaused ) {
playerPaused = false;

Expand Down Expand Up @@ -514,11 +525,6 @@
};

function onPause() {
// Youtube fires a paused event before an ended event.
// We have no need for this.
if ( player.getDuration() === player.getCurrentTime() ) {
return;
}
impl.paused = true;
if ( !playerPaused ) {
playerPaused = true;
Expand Down Expand Up @@ -557,23 +563,6 @@
}
}

function setVolume( aValue ) {
impl.volume = aValue;
if( !mediaReady ) {
addMediaReadyCallback( function() {
setVolume( impl.volume );
});
return;
}
player.setVolume( impl.volume * 100 );
self.dispatchEvent( "volumechange" );
}

function getVolume() {
// YouTube has getVolume(), but for sync access we use impl.volume
return impl.volume;
}

function setMuted( aValue ) {
impl.muted = aValue;
if( !mediaReady ) {
Expand Down Expand Up @@ -681,16 +670,21 @@

volume: {
get: function() {
// Remap from HTML5's 0-1 to YouTube's 0-100 range
var volume = getVolume();
return volume / 100;
return impl.volume
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed a semicolon.

},
set: function( aValue ) {
if( aValue < 0 || aValue > 1 ) {
throw "Volume value must be between 0.0 and 1.0";
}

setVolume( aValue );
impl.volume = aValue;
if( !mediaReady ) {
addMediaReadyCallback( function() {
self.volume = aValue;
});
return;
}
player.setVolume( impl.volume * 100 );
self.dispatchEvent( "volumechange" );
}
},

Expand Down