-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Tech 2.0 additional fixes #2166
Changes from 9 commits
815518e
7a08b45
8040884
39a6d7f
152717e
1766e2c
e3c0285
5d19240
6f455f4
aa998c9
956d77a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import TextTrack from '../tracks/text-track'; | |
import TextTrackList from '../tracks/text-track-list'; | ||
import * as Fn from '../utils/fn.js'; | ||
import log from '../utils/log.js'; | ||
import { createTimeRange } from '../utils/time-ranges.js'; | ||
import { bufferedPercent } from '../utils/buffer.js'; | ||
import window from 'global/window'; | ||
import document from 'global/document'; | ||
|
||
|
@@ -21,7 +21,6 @@ import document from 'global/document'; | |
class Tech extends Component { | ||
|
||
constructor(options={}, ready=function(){}){ | ||
options = options || {}; | ||
// we don't want the tech to report user activity automatically. | ||
// This is done manually in addControlsListeners | ||
options.reportTouchActivity = false; | ||
|
@@ -50,6 +49,9 @@ class Tech extends Component { | |
} | ||
|
||
this.initTextTrackListeners(); | ||
|
||
// Turn on component tap events | ||
this.emitTapEvents(); | ||
} | ||
|
||
/** | ||
|
@@ -109,15 +111,15 @@ class Tech extends Component { | |
this.progressInterval = this.setInterval(Fn.bind(this, function(){ | ||
// Don't trigger unless buffered amount is greater than last time | ||
|
||
let bufferedPercent = this.bufferedPercent(); | ||
let numBufferedPercent = this.bufferedPercent(); | ||
|
||
if (this.bufferedPercent_ !== bufferedPercent) { | ||
if (this.bufferedPercent_ !== numBufferedPercent) { | ||
this.trigger('progress'); | ||
} | ||
|
||
this.bufferedPercent_ = bufferedPercent; | ||
this.bufferedPercent_ = numBufferedPercent; | ||
|
||
if (bufferedPercent === 1) { | ||
if (numBufferedPercent === 1) { | ||
this.stopTrackingProgress(); | ||
} | ||
}), 500); | ||
|
@@ -127,33 +129,12 @@ class Tech extends Component { | |
this.duration_ = this.duration(); | ||
} | ||
|
||
bufferedPercent() { | ||
let bufferedDuration = 0, | ||
start, end; | ||
|
||
if (!this.duration_) { | ||
return 0; | ||
} | ||
|
||
let buffered = this.buffered(); | ||
|
||
if (!buffered || !buffered.length) { | ||
buffered = createTimeRange(0,0); | ||
} | ||
|
||
for (var i=0; i<buffered.length; i++){ | ||
start = buffered.start(i); | ||
end = buffered.end(i); | ||
|
||
// buffered end can be bigger than duration by a very small fraction | ||
if (end > this.duration_) { | ||
end = this.duration_; | ||
} | ||
|
||
bufferedDuration += end - start; | ||
} | ||
buffered() { | ||
return null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this return null? Or should it just return a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is never called outside the unit tests. null to me seems more appropriate because their is no buffer at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this isn't used outside of tests do we need to define it here? Should we change something about the test or whatever relies on buffered? Otherwise I think we should follow the spec.
http://www.w3.org/html/wg/drafts/html/master/semantics.html#dom-media-buffered |
||
} | ||
|
||
return bufferedDuration / this.duration_; | ||
bufferedPercent() { | ||
return bufferedPercent(this.buffered(), this.duration_); | ||
} | ||
|
||
stopTrackingProgress() { | ||
|
@@ -166,21 +147,6 @@ class Tech extends Component { | |
|
||
this.on('play', this.trackCurrentTime); | ||
this.on('pause', this.stopTrackingCurrentTime); | ||
// timeupdate is also called by .currentTime whenever current time is set | ||
|
||
// Watch for native timeupdate event only | ||
var onTimeUpdate = function(e){ | ||
if (e.manuallyTriggered) return; | ||
|
||
this.off('timeupdate', onTimeUpdate); | ||
|
||
// Update known progress support for this playback technology | ||
this.featuresTimeupdateEvents = true; | ||
// Turn off manual progress tracking | ||
this.manualTimeUpdatesOff(); | ||
}; | ||
|
||
this.on('timeupdate', onTimeUpdate); | ||
} | ||
|
||
manualTimeUpdatesOff() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { createTimeRange } from './time-ranges.js'; | ||
|
||
/** | ||
* Compute how much your video has been buffered | ||
* @param {Object} Buffered object | ||
* @param {Number} Total duration | ||
* @return {Number} Percent buffered of the total duration | ||
* @private | ||
*/ | ||
export function bufferedPercent(buffered, duration) { | ||
var bufferedDuration = 0, | ||
start, end; | ||
|
||
if (!duration) { | ||
return 0; | ||
} | ||
|
||
if (!buffered || !buffered.length) { | ||
buffered = createTimeRange(0, 0); | ||
} | ||
|
||
for (let i = 0; i < buffered.length; i++){ | ||
start = buffered.start(i); | ||
end = buffered.end(i); | ||
|
||
// buffered end can be bigger than duration by a very small fraction | ||
if (end > duration) { | ||
end = duration; | ||
} | ||
|
||
bufferedDuration += end - start; | ||
} | ||
|
||
return bufferedDuration / duration; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. For #2033 I want to try to move away from using options like this and instead use the player properties (e.g.
this.autoplay()
), but there's still more work to do to make that even possible. Not something for this PR but just wanted to call it out as something that may change in the near future.