Skip to content

Loading…

T1244 #299

Open
wants to merge 4 commits into from

3 participants

@ScottDowne

No description provided.

@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
@@ -260,6 +263,12 @@
// XXX: cued doesn't seem to fire reliably, bug in youtube api?
break;
}
+
+ if (event.data !== YT.PlayerState.BUFFERING && playerState === YT.PlayerState.BUFFERING) {
@mjschranz Mozilla member

Spacing.

@mjschranz Mozilla member

I'd also consider breaking this onto two lines.

  if ( event.data !== YT.PlayerState.BUFFERING &&
       playerState === YT.PlayerState.BUFFERING ) {
    .....
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
@@ -195,6 +194,10 @@
// fake ready event
firstPlay = false;
+ addMediaReadyCallback( function() {
@mjschranz Mozilla member

addMediaReadyCallback(function() {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
@@ -375,6 +385,20 @@
}
}
+ function monitorBuffered() {
+ var fraction = player.getVideoLoadedFraction();
+
+ if ( lastLoadedFraction !== fraction ) {
+ lastLoadedFraction = fraction;
+
+ onProgress();
+
+ if (fraction >= 1) {
@mjschranz Mozilla member

Spacing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
@@ -627,6 +655,45 @@
get: function() {
return impl.error;
}
+ },
+
+ buffered: {
+ get: function () {
+ var timeRanges = {
+ start: function( index ) {
+ if (index === 0) {
@mjschranz Mozilla member

Spacing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
((4 lines not shown))
+ },
+
+ buffered: {
+ get: function () {
+ var timeRanges = {
+ start: function( index ) {
+ if (index === 0) {
+ return 0;
+ }
+
+ //throw fake DOMException/INDEX_SIZE_ERR
+ throw "INDEX_SIZE_ERR: DOM Exception 1";
+ },
+ end: function( index ) {
+ var duration;
+ if (index === 0) {
@mjschranz Mozilla member

Spacing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
((6 lines not shown))
+ buffered: {
+ get: function () {
+ var timeRanges = {
+ start: function( index ) {
+ if (index === 0) {
+ return 0;
+ }
+
+ //throw fake DOMException/INDEX_SIZE_ERR
+ throw "INDEX_SIZE_ERR: DOM Exception 1";
+ },
+ end: function( index ) {
+ var duration;
+ if (index === 0) {
+ duration = getDuration();
+ if (!duration) {
@mjschranz Mozilla member

Spacing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js
@@ -69,8 +69,36 @@ var testData = {
equal( video.height, 300, "Returned expected parent element height" );
});
- }
+ asyncTest( "YouTube 05 - buffered", function() {
+
+ var video = testData.createMedia( "#video" ),
+ buffered = video.buffered;
+
+ video.addEventListener( "progress", function onProgress() {
+ var end = buffered.end(0);
@mjschranz Mozilla member

Spacing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js
@@ -69,8 +69,36 @@ var testData = {
equal( video.height, 300, "Returned expected parent element height" );
});
- }
+ asyncTest( "YouTube 05 - buffered", function() {
+
+ var video = testData.createMedia( "#video" ),
+ buffered = video.buffered;
+
+ video.addEventListener( "progress", function onProgress() {
+ var end = buffered.end(0);
+ equal( buffered.start(0), 0, "video.buffered range start is always 0" );
@mjschranz Mozilla member

Spacing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js
((21 lines not shown))
+ video.src = testData.videoSrc + "&autoplay=1&loop=1";
+ ok( buffered && typeof buffered === "object", "video.buffered exists" );
+ equal( buffered.length, 1, "video.buffered.length === 1" );
+ equal( buffered.start(0), 0, "video.buffered range start is always 0" );
@mjschranz Mozilla member

Spacing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js
((21 lines not shown))
+ video.src = testData.videoSrc + "&autoplay=1&loop=1";
+ ok( buffered && typeof buffered === "object", "video.buffered exists" );
+ equal( buffered.length, 1, "video.buffered.length === 1" );
+ equal( buffered.start(0), 0, "video.buffered range start is always 0" );
+ equal( buffered.end(0), 0, "video.buffered range end is 0" );
@mjschranz Mozilla member

Spacing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js
((21 lines not shown))
+ video.src = testData.videoSrc + "&autoplay=1&loop=1";
+ ok( buffered && typeof buffered === "object", "video.buffered exists" );
+ equal( buffered.length, 1, "video.buffered.length === 1" );
+ equal( buffered.start(0), 0, "video.buffered range start is always 0" );
+ equal( buffered.end(0), 0, "video.buffered range end is 0" );
+ try {
+ buffered.start(1);
@mjschranz Mozilla member

Spacing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mjschranz mjschranz commented on an outdated diff
wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js
((21 lines not shown))
+ video.src = testData.videoSrc + "&autoplay=1&loop=1";
+ ok( buffered && typeof buffered === "object", "video.buffered exists" );
+ equal( buffered.length, 1, "video.buffered.length === 1" );
+ equal( buffered.start(0), 0, "video.buffered range start is always 0" );
+ equal( buffered.end(0), 0, "video.buffered range end is 0" );
+ try {
+ buffered.start(1);
+ ok( false, "selecting a time range > 0 should throw an error" );
+ } catch (e) {
@mjschranz Mozilla member

Spacing.

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
This page is out of date. Refresh to see the latest.
View
80 wrappers/youtube/popcorn.HTMLYouTubeVideoElement.js
@@ -84,6 +84,9 @@
player,
playerPaused = true,
mediaReadyCallbacks = [],
+ playerState = -1,
+ bufferedInterval,
+ lastLoadedFraction = 0,
currentTimeInterval,
timeUpdateInterval,
firstPlay = true;
@@ -176,10 +179,6 @@
function onPlayerStateChange( event ) {
switch( event.data ) {
- // unstarted
- case -1:
- break;
-
// ended
case YT.PlayerState.ENDED:
onEnded();
@@ -195,10 +194,16 @@
// fake ready event
firstPlay = false;
+ addMediaReadyCallback(function() {
+ bufferedInterval = setInterval( monitorBuffered, 50 );
+ });
+
// Set initial paused state
if( impl.autoplay || !impl.paused ) {
impl.paused = false;
- addMediaReadyCallback( function() { onPlay(); } );
+ addMediaReadyCallback(function() {
+ onPlay();
+ });
} else {
// if a pause happens while seeking, ensure we catch it.
// in youtube seeks fire pause events, and we don't want to listen to that.
@@ -260,6 +265,13 @@
// XXX: cued doesn't seem to fire reliably, bug in youtube api?
break;
}
+
+ if ( event.data !== YT.PlayerState.BUFFERING &&
+ playerState === YT.PlayerState.BUFFERING ) {
+ onProgress();
+ }
+
+ playerState = event.data;
}
function destroyPlayer() {
@@ -267,6 +279,7 @@
return;
}
clearInterval( currentTimeInterval );
+ clearInterval( bufferedInterval );
player.stopVideo();
player.clearVideo();
@@ -375,6 +388,20 @@
}
}
+ function monitorBuffered() {
+ var fraction = player.getVideoLoadedFraction();
+
+ if ( lastLoadedFraction !== fraction ) {
+ lastLoadedFraction = fraction;
+
+ onProgress();
+
+ if ( fraction >= 1 ) {
+ clearInterval( bufferedInterval );
+ }
+ }
+ }
+
function getCurrentTime() {
return impl.currentTime;
}
@@ -436,6 +463,10 @@
}
}
+ function onProgress() {
+ self.dispatchEvent( "progress" );
+ }
+
self.play = function() {
impl.paused = false;
if( !mediaReady ) {
@@ -627,6 +658,45 @@
get: function() {
return impl.error;
}
+ },
+
+ buffered: {
+ get: function () {
+ var timeRanges = {
+ start: function( index ) {
+ if ( index === 0 ) {
+ return 0;
+ }
+
+ //throw fake DOMException/INDEX_SIZE_ERR
+ throw "INDEX_SIZE_ERR: DOM Exception 1";
+ },
+ end: function( index ) {
+ var duration;
+ if ( index === 0 ) {
+ duration = getDuration();
+ if ( !duration ) {
+ return 0;
+ }
+
+ return duration * player.getVideoLoadedFraction();
+ }
+
+ //throw fake DOMException/INDEX_SIZE_ERR
+ throw "INDEX_SIZE_ERR: DOM Exception 1";
+ }
+ };
+
+ Object.defineProperties( timeRanges, {
+ length: {
+ get: function() {
+ return 1;
+ }
+ }
+ });
+
+ return timeRanges;
+ }
}
});
}
View
30 wrappers/youtube/popcorn.HTMLYouTubeVideoElement.unit.js
@@ -69,8 +69,36 @@ var testData = {
equal( video.height, 300, "Returned expected parent element height" );
});
- }
+ asyncTest( "YouTube 05 - buffered", function() {
+
+ var video = testData.createMedia( "#video" ),
+ buffered = video.buffered;
+
+ video.addEventListener( "progress", function onProgress() {
+ var end = buffered.end( 0 );
+ equal( buffered.start( 0 ), 0, "video.buffered range start is always 0" );
+ if ( end > 0 ) {
+ ok( true, "buffered.end( 0 ) " + end + " > 0 on progress" );
+ video.removeEventListener( "progress", onProgress, false );
+ start();
+ } else {
+ ok( end >= 0, "buffered.end( 0 ): " + end + " >= 0 on progress" );
+ }
+ }, false);
+ video.src = testData.videoSrc + "&autoplay=1&loop=1";
+ ok( buffered && typeof buffered === "object", "video.buffered exists" );
+ equal( buffered.length, 1, "video.buffered.length === 1" );
+ equal( buffered.start( 0 ), 0, "video.buffered range start is always 0" );
+ equal( buffered.end( 0 ), 0, "video.buffered range end is 0" );
+ try {
+ buffered.start( 1 );
+ ok( false, "selecting a time range > 0 should throw an error" );
+ } catch ( e ) {
+ ok( e, "selecting a time range > 0 throws an error" );
+ }
+ });
+ }
};
// YouTube tends to fail when the iframes live in the qunit-fixture
Something went wrong with that request. Please try again.