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

Fire "seeking" from the Flash tech #2372

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"safe-json-parse": "^4.0.0",
"videojs-font": "1.3.0",
"videojs-ie8": "1.1.0",
"videojs-swf": "4.7.1",
"videojs-swf": "5.0.0-rc0",
"vtt.js": "git+https://github.com/gkatsev/vtt.js.git#vjs-v0.12.1"
},
"devDependencies": {
Expand Down
15 changes: 14 additions & 1 deletion src/js/tech/flash.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class Flash extends Tech {
window.videojs.Flash.onReady = Flash.onReady;
window.videojs.Flash.onEvent = Flash.onEvent;
window.videojs.Flash.onError = Flash.onError;

this.on('seeked', function() {
this.lastSeekTarget_ = undefined;
});
}

/**
Expand Down Expand Up @@ -157,6 +161,14 @@ class Flash extends Tech {
}
}

/**
* Returns true if the tech is currently seeking.
* @return {boolean} true if seeking
*/
seeking() {
return this.lastSeekTarget_ !== undefined;
}

/**
* Set current time
*
Expand All @@ -171,6 +183,7 @@ class Flash extends Tech {
time = time < seekable.end(seekable.length - 1) ? time : seekable.end(seekable.length - 1);

this.lastSeekTarget_ = time;
this.trigger('seeking');
this.el_.vjs_setProperty('currentTime', time);
super.setCurrentTime();
}
Expand Down Expand Up @@ -284,7 +297,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,ended,videoTracks,audioTracks,videoWidth,videoHeight'.split(',');
const _readOnly = 'error,networkState,readyState,initialTime,duration,startOffsetTime,paused,ended,videoTracks,audioTracks,videoWidth,videoHeight'.split(',');

function _createSetter(attr){
var attrUpper = attr.charAt(0).toUpperCase() + attr.slice(1);
Expand Down
10 changes: 10 additions & 0 deletions test/unit/tech/flash.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ test('Flash.canPlaySource', function() {
test('currentTime', function() {
let getCurrentTime = Flash.prototype.currentTime;
let setCurrentTime = Flash.prototype.setCurrentTime;
let seekingCount = 0;
let seeking = false;
let setPropVal;
let getPropVal;
Expand All @@ -41,6 +42,11 @@ test('currentTime', function() {
seekable(){
return createTimeRange(5, 1000);
},
trigger(event){
if (event === 'seeking') {
seekingCount++;
}
},
seeking(){
return seeking;
}
Expand All @@ -54,22 +60,26 @@ test('currentTime', function() {
// Test the currentTime setter
setCurrentTime.call(mockFlash, 10);
equal(setPropVal, 10, 'currentTime is set on the swf element');
equal(seekingCount, 1, 'triggered seeking');

// Test current time while seeking
setCurrentTime.call(mockFlash, 20);
seeking = true;
result = getCurrentTime.call(mockFlash);
equal(result, 20, 'currentTime is retrieved from the lastSeekTarget while seeking');
notEqual(result, getPropVal, 'currentTime is not retrieved from the element while seeking');
equal(seekingCount, 2, 'triggered seeking');

// clamp seeks to seekable
setCurrentTime.call(mockFlash, 1001);
result = getCurrentTime.call(mockFlash);
equal(result, mockFlash.seekable().end(0), 'clamped to the seekable end');
equal(seekingCount, 3, 'triggered seeking');

setCurrentTime.call(mockFlash, 1);
result = getCurrentTime.call(mockFlash);
equal(result, mockFlash.seekable().start(0), 'clamped to the seekable start');
equal(seekingCount, 4, 'triggered seeking');
});

test('dispose removes the object element even before ready fires', function() {
Expand Down