Skip to content

Commit

Permalink
fix: don't emit synthetic stall if media element reports playback is …
Browse files Browse the repository at this point in the history
…not ready (#89)

Co-authored-by: Joel Keers <[email protected]>
  • Loading branch information
eirikbjornr and jlks authored Dec 11, 2023
1 parent 30da1d8 commit 1d9badf
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/streaming/models/VideoModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ function VideoModel() {
}

stalledStreams.push(type);
if (settings.get().streaming.buffer.emitSyntheticStallEvents && element && stalledStreams.length === 1) {
if (settings.get().streaming.buffer.emitSyntheticStallEvents && element && stalledStreams.length === 1 && element.readyState >= Constants.VIDEO_ELEMENT_READY_STATES.HAVE_FUTURE_DATA) {
logger.debug(`emitting synthetic waiting event and halting playback with playback rate 0`);
// Halt playback until nothing is stalled.
const event = document.createEvent('Event');
event.initEvent('waiting', true, false);
Expand All @@ -247,7 +248,8 @@ function VideoModel() {
}

// If nothing is stalled resume playback.
if (settings.get().streaming.buffer.emitSyntheticStallEvents && element && isStalled() === false && element.playbackRate === 0) {
if (settings.get().streaming.buffer.emitSyntheticStallEvents && element && isStalled() === false && element.playbackRate === 0 && element.readyState >= Constants.VIDEO_ELEMENT_READY_STATES.HAVE_FUTURE_DATA) {
logger.debug(`emitting synthetic playing event (if not paused) and resuming playback with playback rate: ${previousPlaybackRate || 1}`);
setPlaybackRate(previousPlaybackRate || 1);
if (!element.paused) {
const event = document.createEvent('Event');
Expand Down

0 comments on commit 1d9badf

Please sign in to comment.