Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up durationchange process in the player #2552

Merged
merged 1 commit into from
Sep 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ CHANGELOG
* @heff added back the default cdn url for the swf ([view](https://github.com/videojs/video.js/pull/2533))
* @gkatsev fixed the default state of userActive ([view](https://github.com/videojs/video.js/pull/2557))
* @heff fixed event bubbling in IE8 ([view](https://github.com/videojs/video.js/pull/2563))
* @heff cleaned up internal duration handling ([view](https://github.com/videojs/video.js/pull/2552))

--------------------

Expand Down
57 changes: 23 additions & 34 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ class Player extends Component {
this.techCall('setVolume', this.cache_.volume);
}

// Update the duration if available
this.handleTechDurationChange();

// Chrome and Safari both have issues with autoplay.
// In Safari (5.1.1), when we move the video element into the container div, autoplay doesn't work.
// In Chrome (15), if you have autoplay + a poster + no controls, the video gets hidden (but audio plays)
Expand Down Expand Up @@ -867,8 +870,7 @@ class Player extends Component {
* @event durationchange
*/
handleTechDurationChange() {
this.updateDuration();
this.trigger('durationchange');
this.duration(this.techGet('duration'));
}

/**
Expand Down Expand Up @@ -933,31 +935,6 @@ class Player extends Component {
event.preventDefault();
}

/**
* Update the duration of the player using the tech
*
* @private
* @method updateDuration
*/
updateDuration() {
// Allows for caching value instead of asking player each time.
// We need to get the techGet response and check for a value so we don't
// accidentally cause the stack to blow up.
var duration = this.techGet('duration');
if (duration) {
if (duration < 0) {
duration = Infinity;
}
this.duration(duration);
// Determine if the stream is live and propagate styles down to UI.
if (duration === Infinity) {
this.addClass('vjs-live');
} else {
this.removeClass('vjs-live');
}
}
}

/**
* Fired when the player switches in or out of fullscreen mode
*
Expand Down Expand Up @@ -1277,19 +1254,31 @@ class Player extends Component {
* @method duration
*/
duration(seconds) {
if (seconds !== undefined) {
if (seconds === undefined) {
return this.cache_.duration || 0;
}

// cache the last set value for optimized scrubbing (esp. Flash)
this.cache_.duration = parseFloat(seconds);
seconds = parseFloat(seconds) || 0;

return this;
// Standardize on Inifity for signaling video is live
if (seconds < 0) {
seconds = Infinity;
}

if (this.cache_.duration === undefined) {
this.updateDuration();
if (seconds !== this.cache_.duration) {
// Cache the last set value for optimized scrubbing (esp. Flash)
this.cache_.duration = seconds;

if (seconds === Infinity) {
this.addClass('vjs-live');
} else {
this.removeClass('vjs-live');
}

this.trigger('durationchange');
}

return this.cache_.duration || 0;
return this;
}

/**
Expand Down