[t1443] Add setter method for duration on NullVideo #295

Open
wants to merge 2 commits into
from
View
@@ -245,6 +245,20 @@
// Check for no duration info (NaN)
videoDurationPlus = duration != duration ? Number.MAX_VALUE : duration + 1;
+ self.on( "durationchange", function() {
+ var byEnd = self.data.trackEvents.byEnd,
+ byStart = self.data.trackEvents.byStart,
+ newDuration = self.duration(),
+ newEndPaddingDuration = newDuration != newDuration ? Number.MAX_VALUE : newDuration + 1;
+
+ byEnd.splice( byEnd.length - 1, 1 );
+ byStart.splice( byStart.length - 1, 1 );
+ Popcorn.addTrackEvent( self, {
+ start: newEndPaddingDuration,
+ end: newEndPaddingDuration
+ });
+ });
+
Popcorn.addTrackEvent( self, {
start: videoDurationPlus,
end: videoDurationPlus
@@ -371,6 +371,12 @@
duration: {
get: function() {
return getDuration();
+ },
+ set: function( val ) {
+ if ( !isNaN( val ) ) {
+ player.duration = val;
+ self.dispatchEvent( "durationchange" );
+ }
}
},
@@ -6,6 +6,26 @@ var testData = {
createMedia: function( id ) {
return Popcorn.HTMLNullVideoElement( id );
+ },
+
+ playerSpecificAsyncTests: function() {
+
+ asyncTest( "NullVideo 01 - durationchange fired after setting duration", 1, function() {
+
+ var video = testData.createMedia( "#video" );
+
+ video.src = testData.videoSrc;
+
+ video.addEventListener( "durationchange", function onDurationChange() {
+ video.removeEventListener( "durationchange", onDurationChange, false );
+
+ equal( video.duration, 35, "Null video properly had it's new duration set." );
+ start();
+ }, false );
+
+ video.duration = 35;
+ });
+
}
};