Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Open
wants to merge 3 commits into from

2 participants

@ScottDowne
Owner

No description provided.

wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
@@ -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
@mjschranz Owner

Missed a semicolon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 20, 2014
  1. @ScottDowne
Commits on Jan 21, 2014
  1. @ScottDowne

    fixed last test

    ScottDowne authored
  2. @ScottDowne

    lint

    ScottDowne authored
This page is out of date. Refresh to see the latest.
Showing with 36 additions and 38 deletions.
  1. +36 −38 wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
View
74 wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
@@ -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();
+ }
});
}
@@ -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;
@@ -210,26 +216,28 @@
}
function onFirstPause() {
+ removeYouTubeEvent( "pause", onFirstPause );
if ( player.getCurrentTime() > 0 ) {
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.
function onFirstPlay() {
+ removeYouTubeEvent( "play", onFirstPlay );
if ( player.getCurrentTime() === 0 ) {
setTimeout( onFirstPlay, 0 );
return;
}
- removeYouTubeEvent( "play", onFirstPlay );
addYouTubeEvent( "pause", onFirstPause );
-
player.seekTo( 0 );
player.pauseVideo();
}
@@ -268,7 +276,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
@@ -294,6 +306,11 @@
if( !( playerReady && player ) ) {
return;
}
+
+ removeYouTubeEvent( "buffering", onBuffering );
+ removeYouTubeEvent( "ended", onEnded );
+ removeYouTubeEvent( "play", onPlay );
+ removeYouTubeEvent( "pause", onPause );
onPause();
mediaReady = false;
loopedPlay = false;
@@ -477,7 +494,6 @@
}
function onPlay() {
-
if( impl.ended ) {
changeCurrentTime( 0 );
impl.ended = false;
@@ -485,7 +501,6 @@
timeUpdateInterval = setInterval( onTimeUpdate,
self._util.TIMEUPDATE_MS );
impl.paused = false;
-
if( playerPaused ) {
playerPaused = false;
@@ -514,11 +529,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;
@@ -557,23 +567,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 ) {
@@ -681,16 +674,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;
},
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" );
}
},
Something went wrong with that request. Please try again.