feat: add preservePosition option to loadVideoSource
This commit is contained in:
@@ -43,14 +43,19 @@ const shouldUseHLS = (type: string | undefined, url: string): boolean => {
|
|||||||
* Some browsers can be flaky when switching between HLS URLs while playing. Clearing `src` first
|
* Some browsers can be flaky when switching between HLS URLs while playing. Clearing `src` first
|
||||||
* ensures the media element fully resets before the new URL is set.
|
* ensures the media element fully resets before the new URL is set.
|
||||||
*/
|
*/
|
||||||
export const loadVideoSource = (url: string, type?: string, startTimeSeconds?: number): void => {
|
export const loadVideoSource = (
|
||||||
|
url: string,
|
||||||
|
type?: string,
|
||||||
|
startTimeSeconds?: number,
|
||||||
|
preservePosition: boolean = true,
|
||||||
|
): void => {
|
||||||
if (!url) {
|
if (!url) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const wasPlaying = !state.elements.video.paused;
|
const wasPlaying = !state.elements.video.paused;
|
||||||
const prevDisplayTime = displayTimeFromAbsolute(state.elements.video.currentTime);
|
const prevDisplayTime = displayTimeFromAbsolute(state.elements.video.currentTime);
|
||||||
const shouldPreservePosition = prevDisplayTime > 0;
|
const shouldPreservePosition = preservePosition && prevDisplayTime > 0;
|
||||||
|
|
||||||
// Fully reset the element before setting a new source.
|
// Fully reset the element before setting a new source.
|
||||||
destroyVideoSource();
|
destroyVideoSource();
|
||||||
|
|||||||
Reference in New Issue
Block a user