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

Fix VideoModel currentTime and seeking #3872

Merged
Changes from 2 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
19 changes: 11 additions & 8 deletions src/streaming/models/VideoModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function VideoModel() {
let instance,
logger,
element,
_currentTime,
TTMLRenderingDiv,
previousPlaybackRate;

Expand All @@ -59,6 +60,7 @@ function VideoModel() {

function setup() {
logger = Debug(context).getInstance().getLogger(instance);
_currentTime = NaN;
}

function initialize() {
Expand Down Expand Up @@ -88,13 +90,12 @@ function VideoModel() {

//TODO Move the DVR window calculations from MediaPlayer to Here.
function setCurrentTime(currentTime, stickToBuffered) {
_currentTime = currentTime;
waitForReadyState(Constants.VIDEO_ELEMENT_READY_STATES.HAVE_METADATA, () => {
if (element) {
//_currentTime = currentTime;

// We don't set the same currentTime because it can cause firing unexpected Pause event in IE11
// providing playbackRate property equals to zero.
if (element.currentTime === currentTime) {
if (element.currentTime === _currentTime) {
return;
dsilhavy marked this conversation as resolved.
Show resolved Hide resolved
}

Expand All @@ -104,12 +105,14 @@ function VideoModel() {
// set currentTime even if readyState = 0.
// setTimeout is used to workaround InvalidStateError in IE11
try {
currentTime = stickToBuffered ? stickTimeToBuffered(currentTime) : currentTime;
element.currentTime = currentTime;
_currentTime = stickToBuffered ? stickTimeToBuffered(_currentTime) : _currentTime;
element.currentTime = _currentTime;
_currentTime = NaN;
} catch (e) {
if (element.readyState === 0 && e.code === e.INVALID_STATE_ERR) {
setTimeout(function () {
element.currentTime = currentTime;
element.currentTime = _currentTime;
_currentTime = NaN;
}, 400);
}
}
Expand Down Expand Up @@ -287,11 +290,11 @@ function VideoModel() {
}

function isSeeking() {
return element ? element.seeking : null;
return element ? (element.seeking || !isNaN(_currentTime)) : null;
}

function getTime() {
return element ? element.currentTime : null;
return element ? (!isNaN(_currentTime) ? _currentTime : element.currentTime) : null;
}

function getPlaybackRate() {
Expand Down