Skip to content

Commit

Permalink
Made duration setable and cached.
Browse files Browse the repository at this point in the history
  • Loading branch information
heff committed Apr 25, 2012
1 parent b0061f0 commit 8c73d8f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/player.js
Expand Up @@ -75,6 +75,7 @@ _V_.Player = _V_.Component.extend({
this.on("play", this.onPlay);
this.on("pause", this.onPause);
this.on("progress", this.onProgress);
this.on("durationchange", this.onDurationChange);
this.on("error", this.onError);

// When the API is ready, loop through the components and add to the player.
Expand Down Expand Up @@ -358,6 +359,12 @@ _V_.Player = _V_.Component.extend({
}
},

// Update duration with durationchange event
// Allows for cacheing value instead of asking player each time.
onDurationChange: function(){
this.duration(this.techGet("duration"));
},

onError: function(e) {
_V_.log("Video Error", e);
},
Expand Down Expand Up @@ -470,8 +477,16 @@ _V_.Player = _V_.Component.extend({

// http://dev.w3.org/html5/spec/video.html#dom-media-duration
// Duration should return NaN if not available. ParseFloat will turn false-ish values to NaN.
duration: function(){
return parseFloat(this.techGet("duration"));
duration: function(seconds){
if (seconds !== undefined) {

// Cache the last set value for optimiized scrubbing (esp. Flash)
this.values.duration = parseFloat(seconds);

return this;
}

return this.values.duration;
},

// Calculates how much time is left. Not in spec, but useful.
Expand Down

0 comments on commit 8c73d8f

Please sign in to comment.