mirror of
https://github.com/videojs/video.js.git
synced 2025-02-04 11:43:27 +02:00
Store last seek time in the Flash tech
Instead of caching the last seek time at the player level, cache it in the Flash tech. The only place this value was used was in the progress controls when Flash was loaded, so this simplifies the logic in that component and pushes the hack down into a single location at least.
This commit is contained in:
parent
1cd81ad258
commit
dd8c25e8d5
@ -68,25 +68,7 @@ vjs.SeekBar.prototype.updateARIAAttributes = function(){
|
||||
};
|
||||
|
||||
vjs.SeekBar.prototype.getPercent = function(){
|
||||
var currentTime;
|
||||
// Flash RTMP provider will not report the correct time
|
||||
// immediately after a seek. This isn't noticeable if you're
|
||||
// seeking while the video is playing, but it is if you seek
|
||||
// while the video is paused.
|
||||
if (this.player_.techName === 'Flash' && this.player_.seeking()) {
|
||||
var cache = this.player_.getCache();
|
||||
if (cache.lastSetCurrentTime) {
|
||||
currentTime = cache.lastSetCurrentTime;
|
||||
}
|
||||
else {
|
||||
currentTime = this.player_.currentTime();
|
||||
}
|
||||
}
|
||||
else {
|
||||
currentTime = this.player_.currentTime();
|
||||
}
|
||||
|
||||
return currentTime / this.player_.duration();
|
||||
return this.player_.currentTime() / this.player_.duration();
|
||||
};
|
||||
|
||||
vjs.SeekBar.prototype.onMouseDown = function(event){
|
||||
|
@ -60,7 +60,9 @@ vjs.Flash = vjs.MediaTechController.extend({
|
||||
'id': objId,
|
||||
'name': objId, // Both ID and Name needed or swf to identifty itself
|
||||
'class': 'vjs-tech'
|
||||
}, options['attributes'])
|
||||
}, options['attributes']),
|
||||
|
||||
lastSeekTarget
|
||||
;
|
||||
|
||||
// If source was supplied pass as a flash var.
|
||||
@ -75,6 +77,17 @@ vjs.Flash = vjs.MediaTechController.extend({
|
||||
}
|
||||
}
|
||||
|
||||
this['setCurrentTime'] = function(time){
|
||||
lastSeekTarget = time;
|
||||
this.el_.vjs_setProperty('currentTime', time);
|
||||
};
|
||||
this['currentTime'] = function(time){
|
||||
if (this.seeking()) {
|
||||
return lastSeekTarget;
|
||||
}
|
||||
return this.el_.vjs_getProperty('currentTime');
|
||||
};
|
||||
|
||||
// Add placeholder to player div
|
||||
vjs.insertFirst(placeHolder, parentEl);
|
||||
|
||||
@ -302,9 +315,9 @@ vjs.Flash.prototype.enterFullScreen = function(){
|
||||
|
||||
// Create setters and getters for attributes
|
||||
var api = vjs.Flash.prototype,
|
||||
readWrite = 'rtmpConnection,rtmpStream,preload,currentTime,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted'.split(','),
|
||||
readWrite = 'rtmpConnection,rtmpStream,preload,defaultPlaybackRate,playbackRate,autoplay,loop,mediaGroup,controller,controls,volume,muted,defaultMuted'.split(','),
|
||||
readOnly = 'error,currentSrc,networkState,readyState,seeking,initialTime,duration,startOffsetTime,paused,played,seekable,ended,videoTracks,audioTracks,videoWidth,videoHeight,textTracks'.split(',');
|
||||
// Overridden: buffered
|
||||
// Overridden: buffered, currentTime
|
||||
|
||||
/**
|
||||
* @this {*}
|
||||
|
@ -646,9 +646,6 @@ vjs.Player.prototype.paused = function(){
|
||||
vjs.Player.prototype.currentTime = function(seconds){
|
||||
if (seconds !== undefined) {
|
||||
|
||||
// cache the last set value for smoother scrubbing
|
||||
this.cache_.lastSetCurrentTime = seconds;
|
||||
|
||||
this.techCall('setCurrentTime', seconds);
|
||||
|
||||
// improve the accuracy of manual timeupdates
|
||||
|
@ -62,3 +62,37 @@ test('test canPlaySource', function() {
|
||||
ok(!canPlaySource({ type: 'video/webm; codecs="vp8, vorbis"' }));
|
||||
ok(!canPlaySource({ type: 'video/webm' }));
|
||||
});
|
||||
|
||||
test('currentTime is the seek target during seeking', function() {
|
||||
var noop = function() {},
|
||||
seeking = false,
|
||||
parentEl = document.createElement('div'),
|
||||
tech = new vjs.Flash({
|
||||
id: noop,
|
||||
on: noop,
|
||||
options_: {}
|
||||
}, {
|
||||
'parentEl': parentEl
|
||||
}),
|
||||
currentTime;
|
||||
|
||||
tech.el().vjs_setProperty = function(property, value) {
|
||||
if (property === 'currentTime') {
|
||||
currentTime = value;
|
||||
}
|
||||
};
|
||||
tech.el().vjs_getProperty = function(name) {
|
||||
if (name === 'currentTime') {
|
||||
return currentTime;
|
||||
} else if (name === 'seeking') {
|
||||
return seeking;
|
||||
}
|
||||
};
|
||||
|
||||
currentTime = 3;
|
||||
strictEqual(3, tech.currentTime(), 'currentTime is retreived from the SWF');
|
||||
|
||||
tech['setCurrentTime'](7);
|
||||
seeking = true;
|
||||
strictEqual(7, tech.currentTime(), 'during seeks the target time is returned');
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user