From ea2d5c4540431e477b07e4880392bb775a9d70f0 Mon Sep 17 00:00:00 2001 From: stevenaw Date: Tue, 8 Mar 2011 00:08:43 -0500 Subject: [PATCH] [#280] Bugfixes in popcorn core for duration, mute implementation in player --- players/vimeo/popcorn.vimeo.html | 2 +- players/vimeo/popcorn.vimeo.js | 13 +++++-- players/vimeo/popcorn.vimeo.unit.js | 16 +++++++-- popcorn.js | 56 ++++++++++++++++------------- 4 files changed, 57 insertions(+), 30 deletions(-) diff --git a/players/vimeo/popcorn.vimeo.html b/players/vimeo/popcorn.vimeo.html index 507f223..20b5e51 100644 --- a/players/vimeo/popcorn.vimeo.html +++ b/players/vimeo/popcorn.vimeo.html @@ -63,7 +63,7 @@ // Mute document.getElementById( "btnMute" ).addEventListener( "click", function() { - player.volume( 0 ); + player.mute(); }, false); // Hook into player events diff --git a/players/vimeo/popcorn.vimeo.js b/players/vimeo/popcorn.vimeo.js index 2ac1b29..0e68641 100644 --- a/players/vimeo/popcorn.vimeo.js +++ b/players/vimeo/popcorn.vimeo.js @@ -83,6 +83,7 @@ * volume ( get only, set by calling setVolume() ) * * load() function + * mute() function * * Unsupported media attributes: * buffered @@ -233,9 +234,9 @@ // Better to store them here than on the DOM this.objVars = { paused: true, - duration: -1, + duration: Number.NaN, ended: 0, - currentTime: -1, + currentTime: Number.NaN, volume: 1, loop: 0, initialTime: 0, @@ -420,6 +421,14 @@ duration: function() { return this.objVars.duration; }, + mute: function() { + if ( !this.muted() ) { + this.objVars.oldVol = this.objVars.volume; + this.volume( 0 ); + } else { + this.volume( this.objVars.oldVol ); + } + }, muted: function() { return this.objVars.volume === 0; }, diff --git a/players/vimeo/popcorn.vimeo.unit.js b/players/vimeo/popcorn.vimeo.unit.js index 471e0fd..036fd3c 100644 --- a/players/vimeo/popcorn.vimeo.unit.js +++ b/players/vimeo/popcorn.vimeo.unit.js @@ -20,7 +20,7 @@ test("Popcorn Vimeo Plugin", function () { } var popped = Popcorn.vimeo( "player_1", "http://vimeo.com/11127501" ), - expects = 21, + expects = 23, playCount = 0, pauseCount = 0, count = 0, @@ -48,11 +48,21 @@ test("Popcorn Vimeo Plugin", function () { ok( popped.video.muted(), "Muted set when player volume 0" ); plus(); - popped.volume( 1 ); + popped.volume( 0.333 ); } else if ( timesCalled === 2 ) { ok( !popped.video.muted(), "Unmuted when volume not 0" ); plus(); + popped.mute(); + } else if ( timesCalled === 3 ) { + ok( popped.video.muted(), "Mute mutes when volume is non-zero" ); + plus(); + + popped.mute(); + } else if ( timesCalled === 4 ) { + equals( popped.volume(), 0.333, "Mute unmutes to last volume" ); + plus(); + popped.exec( 4, function() { popped.video.unload(); }); @@ -110,7 +120,7 @@ test("Popcorn Vimeo Plugin", function () { expect( expects ); - stop( 20000 ); + stop( /* 20000 */ ); ok( "vimeo" in Popcorn, "Vimeo is a method of Popcorn" ); plus(); diff --git a/popcorn.js b/popcorn.js index fc98f3e..5a91650 100644 --- a/popcorn.js +++ b/popcorn.js @@ -78,14 +78,17 @@ } - matches = rIdExp.exec( entity ); - - if ( matches.length && matches[2] ) { - elem = document.getElementById(matches[2]); - } + if ( (typeof entity) == "string" ) { + matches = rIdExp.exec( entity ); + if ( matches.length && matches[2] ) { + elem = document.getElementById(matches[2]); + } - this.video = elem ? elem : null; + this.video = elem ? elem : null; + } else if ( entity instanceof Object ) { + this.video = entity; + } this.data = { history: [], @@ -111,7 +114,7 @@ // adding padding to the front and end of the arrays // this is so we do not fall off either end - var duration = that.video.duration; + var duration = typeof that.video.duration === "function" ? that.video.duration() : that.video.duration; // Check for no duration info (NaN) var videoDurationPlus = duration != duration ? Number.MAX_VALUE : duration + 1; @@ -128,6 +131,11 @@ tracksByEnd = tracks.byEnd, tracksByStart = tracks.byStart; + + if (typeof this.currentTime === "function") { + currentTime = this.currentTime(); + } + // Playbar advancing if ( previousTime < currentTime ) { @@ -214,7 +222,9 @@ } }; - isReady( this ); + if ( this.video ) { + isReady( this ); + } return this; } @@ -293,29 +303,26 @@ // Build methods, store in object that is returned and passed to extend Popcorn.forEach( methods.split(/\s+/g), function( name ) { - - ret[ name ] = function( arg ) { - if ( typeof this.video[name] === "function" ) { - // Looad, play, pause, mute do not reeturn a value when nothing is passed to them - if ( /load|play|pause|mute/.test( name ) || arg !== false && arg !== null && typeof arg !== "undefined" ) { - - this.video[ name ](); - return this; - - } - - return this.video[ name ]( arg ); - } + ret[ name ] = function( arg ) { + var isFunc = typeof this.video[name] === "function"; - if ( arg !== false && arg !== null && typeof arg !== "undefined" ) { + if ( /load|play|pause|mute/.test( name ) || ( arg !== false && arg !== null && typeof arg !== "undefined" ) ) { - this.video[ name ] = arg; + if ( isFunc ) { + this.video[ name ]( arg ); + } else { + this.video[ name ] = arg; + } return this; } + if ( isFunc ) { + return this.video[ name ](); + } + return this.video[ name ]; }; }); @@ -908,7 +915,7 @@ settings.ajax.open( settings.type, settings.url, settings.async ); - settings.ajax.send( settings.data = null ? null : settings.data ); + settings.ajax.send( settings.data || null ); return Popcorn.xhr.httpData( settings ); } @@ -1108,3 +1115,4 @@ }, false ); })(window, window.document); + -- 2.43.0