From 06abd5f0ab23565f23e53ba26d13426bfdbf3bfd Mon Sep 17 00:00:00 2001 From: nklhrstv Date: Fri, 20 May 2022 09:41:46 +0300 Subject: [PATCH] set startTime after metadata is loaded --- src/HTMLVideo/HTMLVideo.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/HTMLVideo/HTMLVideo.js b/src/HTMLVideo/HTMLVideo.js index 627bb4c..890cd27 100644 --- a/src/HTMLVideo/HTMLVideo.js +++ b/src/HTMLVideo/HTMLVideo.js @@ -75,6 +75,11 @@ function HTMLVideo(options) { onPropChanged('buffering'); onPropChanged('buffered'); }; + videoElement.onloadedmetadata = function() { + onPropChanged('buffering'); + onPropChanged('buffered'); + setProp('time', startTime); + }; videoElement.onvolumechange = function() { onPropChanged('volume'); onPropChanged('muted'); @@ -96,6 +101,7 @@ function HTMLVideo(options) { var events = new EventEmitter(); var destroyed = false; var stream = null; + var startTime = null; var subtitlesOffset = 0; var observedProps = { stream: false, @@ -361,7 +367,7 @@ function HTMLVideo(options) { break; } case 'time': { - if (stream !== null && propValue !== null && isFinite(propValue)) { + if (stream !== null && videoElement.readyState >= videoElement.HAVE_METADATA && propValue !== null && isFinite(propValue)) { videoElement.currentTime = parseInt(propValue, 10) / 1000; } @@ -484,9 +490,9 @@ function HTMLVideo(options) { command('unload'); if (commandArgs && commandArgs.stream && typeof commandArgs.stream.url === 'string') { stream = commandArgs.stream; + startTime = commandArgs.time; onPropChanged('stream'); videoElement.autoplay = typeof commandArgs.autoplay === 'boolean' ? commandArgs.autoplay : true; - videoElement.currentTime = commandArgs.time !== null && isFinite(commandArgs.time) ? parseInt(commandArgs.time, 10) / 1000 : 0; onPropChanged('paused'); onPropChanged('time'); onPropChanged('duration'); @@ -535,6 +541,7 @@ function HTMLVideo(options) { } case 'unload': { stream = null; + startTime = null; Array.from(videoElement.textTracks).forEach(function(track) { track.oncuechange = null; }); @@ -585,6 +592,7 @@ function HTMLVideo(options) { videoElement.oncanplay = null; videoElement.canplaythrough = null; videoElement.onloadeddata = null; + videoElement.onloadedmetadata = null; videoElement.onvolumechange = null; videoElement.onratechange = null; videoElement.textTracks.onchange = null;