Skip to content

Commit

Permalink
feat: add heuristics for deferring played during seek/buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
martinstark committed Sep 17, 2024
1 parent 349ebd0 commit 9132248
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/media-event-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ export const getMediaEventFilter = ({
};

callback(FilteredMediaEvent.BUFFERED);

if (state.deferPlayingEvent) {
onPlaying();
}
} else if (state.seeking) {
state = {
...state,
Expand All @@ -177,6 +181,10 @@ export const getMediaEventFilter = ({
};

callback(FilteredMediaEvent.SEEKED);

if (state.deferPlayingEvent) {
onPlaying();
}
}
}
};
Expand Down Expand Up @@ -225,6 +233,10 @@ export const getMediaEventFilter = ({
};

callback(FilteredMediaEvent.SEEKED);

if (state.deferPlayingEvent) {
onPlaying();
}
}
};

Expand Down Expand Up @@ -289,7 +301,18 @@ export const getMediaEventFilter = ({

// guard for when an engine sets playbackRate to 0 to continue buffering
// recover in "ratechange" event
if (mediaElement.playbackRate === 0) {
// and defer valid playing events occurring during seeking or buffering
// recover in seeked / canplaythrough event
if (
mediaElement.playbackRate === 0 ||
// For a playing event to be valid the video must first have
// been paused and a play request must have been made. Playing
// should not trigger during seeks or buffer, therefore we defer
// it.
(state.paused &&
state.playRequested &&
(state.seeking || state.buffering))
) {
state = {
...state,
deferPlayingEvent: true,
Expand Down

0 comments on commit 9132248

Please sign in to comment.