1
0
mirror of https://github.com/videojs/video.js.git synced 2025-01-10 23:30:03 +02:00

@dmlap added support for the seekable property. closes #2208

This commit is contained in:
David LaPalomento 2015-06-08 13:47:04 -07:00 committed by heff
parent 3857d78261
commit 0be74e51ff
6 changed files with 64 additions and 2 deletions

View File

@ -48,6 +48,7 @@ CHANGELOG
* @arwidt added Swedish and Finnish translations ([view](https://github.com/videojs/video.js/pull/2189))
* @heff moved all the CDN logic into videojs/cdn ([view](https://github.com/videojs/video.js/pull/2230))
* @mmcc fixed the progress handle transition jerkiness ([view](https://github.com/videojs/video.js/pull/2219))
* @dmlap added support for the seekable property ([view](https://github.com/videojs/video.js/pull/2208))
--------------------

View File

@ -1818,6 +1818,13 @@ class Player extends Component {
*/
seeking() { return this.techGet('seeking'); }
/**
* Returns the TimeRanges of the media that are currently available
* for seeking to.
* @return {TimeRanges} the seekable intervals of the media timeline
*/
seekable() { return this.techGet('seekable'); }
reportUserActivity(event) {
this.userActivity_ = true;
}

View File

@ -160,6 +160,14 @@ class Flash extends Tech {
// poster images are not handled by the Flash tech so make this a no-op
setPoster() {}
seekable() {
const duration = this.duration();
if (duration === 0) {
return createTimeRange();
}
return createTimeRange(0, duration);
}
buffered() {
return createTimeRange(0, this.el_.vjs_getProperty('buffered'));
}
@ -178,7 +186,7 @@ class Flash extends Tech {
// Create setters and getters for attributes
const _api = Flash.prototype;
const _readWrite = 'rtmpConnection,rtmpStream,preload,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted'.split(',');
const _readOnly = 'error,networkState,readyState,seeking,initialTime,duration,startOffsetTime,paused,played,seekable,ended,videoTracks,audioTracks,videoWidth,videoHeight'.split(',');
const _readOnly = 'error,networkState,readyState,seeking,initialTime,duration,startOffsetTime,paused,played,ended,videoTracks,audioTracks,videoWidth,videoHeight'.split(',');
function _createSetter(attr){
var attrUpper = attr.charAt(0).toUpperCase() + attr.slice(1);

View File

@ -267,6 +267,7 @@ class Html5 extends Tech {
error() { return this.el_.error; }
seeking() { return this.el_.seeking; }
seekable() { return this.el_.seekable; }
ended() { return this.el_.ended; }
defaultMuted() { return this.el_.defaultMuted; }

View File

@ -9,6 +9,17 @@
* @private
*/
export function createTimeRange(start, end){
if (start === undefined && end === undefined) {
return {
length: 0,
start: function() {
throw new Error('This TimeRanges object is empty');
},
end: function() {
throw new Error('This TimeRanges object is empty');
}
};
}
return {
length: 1,
start: function() { return start; },

View File

@ -1,7 +1,16 @@
import Flash from '../../../src/js/tech/flash.js';
import document from 'global/document';
q.module('Flash');
let tech;
q.module('Flash', {
setup() {
tech = new Flash({});
},
teardown() {
tech.dispose();
}
});
var streamToPartsAndBack = function(url) {
var parts = Flash.streamToParts(url);
@ -177,3 +186,28 @@ test('canHandleSource should be able to work with src objects without a type', f
equal('maybe', canHandleSource({src: 'test.video.flv'}), 'should guess that it is a flash video');
equal('', canHandleSource({src: 'test.video.wgg'}), 'should return empty string if it can not play the video');
});
test('seekable should be for the length of the loaded video', function() {
let duration = 23;
// mock out duration
tech.el().vjs_getProperty = function(name) {
if (name === 'duration') {
return duration;
}
};
equal(tech.seekable().length, 1, 'seekable is non-empty');
equal(tech.seekable().start(0), 0, 'starts at zero');
equal(tech.seekable().end(0), duration, 'ends at the duration');
});
test('seekable should be empty if no video is loaded', function() {
// mock out duration
tech.el().vjs_getProperty = function(name) {
if (name === 'duration') {
return 0;
}
};
equal(tech.seekable().length, 0, 'seekable is empty');
});