diff --git a/src/video/state/init.ts b/src/video/state/init.ts index 438841e4..c13021b7 100644 --- a/src/video/state/init.ts +++ b/src/video/state/init.ts @@ -12,7 +12,7 @@ export function resetForSource(s: VideoPlayerState) { isDragSeeking: false, isFirstLoading: true, hasPlayedOnce: false, - volume: 0, + volume: state.mediaPlaying.volume, // volume settings needs to persist through resets }; state.progress = { time: 0, diff --git a/src/video/state/providers/videoStateProvider.ts b/src/video/state/providers/videoStateProvider.ts index eb88f5df..9791f53f 100644 --- a/src/video/state/providers/videoStateProvider.ts +++ b/src/video/state/providers/videoStateProvider.ts @@ -129,18 +129,22 @@ export function createVideoStateProvider( }, setSource(source) { if (!source) { + resetStateForSource(descriptor, state); player.src = ""; state.source = null; - resetStateForSource(descriptor, state); updateSource(descriptor, state); return; } + // reset before assign new one so the old HLS instance gets destroyed + resetStateForSource(descriptor, state); + if (source?.type === MWStreamType.HLS) { if (player.canPlayType("application/vnd.apple.mpegurl")) { + // HLS supported natively by browser player.src = source.source; } else { - // HLS support + // HLS through HLS.js if (!Hls.isSupported()) { state.error = { name: `Not supported`, @@ -168,6 +172,7 @@ export function createVideoStateProvider( hls.loadSource(source.source); } } else if (source.type === MWStreamType.MP4) { + // standard MP4 stream player.src = source.source; } @@ -178,7 +183,6 @@ export function createVideoStateProvider( url: source.source, caption: null, }; - resetStateForSource(descriptor, state); updateSource(descriptor, state); }, setCaption(id, url) {