Permalink
Browse files

Merge branch 'feature/duration-cacheing'

  • Loading branch information...
2 parents b0061f0 + 8bd70b6 commit 048b808153ffb5993173159c5213122de643b482 Steve Heffernan committed Apr 25, 2012
Showing with 18 additions and 2 deletions.
  1. +1 −0 CHANGELOG.md
  2. +17 −2 src/player.js
View
@@ -1,3 +1,4 @@
+* Duration is now setable (need ed for HLS m3u8 files)
* Event binders (on/off/one) now return the player instance
* Stopped player from going back to beginningg on ended event.
* Added support for percent width/height and fluid layouts
View
@@ -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.
@@ -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);
},
@@ -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.

0 comments on commit 048b808

Please sign in to comment.