diff --git a/src/components/QualitySelectorControllBar.ts b/src/components/QualitySelectorControllBar.ts index 1109b9e3f..448c2d7ad 100644 --- a/src/components/QualitySelectorControllBar.ts +++ b/src/components/QualitySelectorControllBar.ts @@ -1,9 +1,11 @@ import videojs from 'video.js'; -const changeVideoQuality = (quality: string) => { +const changeVideoQuality = (quality: string, player: any) => { const currentUrl = new URL(window.location.href); currentUrl.searchParams.set('quality', quality); - window.location.href = currentUrl.href; + const newUrl = `${currentUrl.pathname}?${currentUrl.searchParams.toString()}`; + window.history.pushState({ path: newUrl }, '', newUrl); + player.qualitySelector(quality); }; class QualitySelectorControllBar extends videojs.getComponent('Button') { @@ -42,15 +44,16 @@ class QualitySelectorControllBar extends videojs.getComponent('Button') { dropUpMenuElement.querySelectorAll('li').forEach((item) => { item.addEventListener('click', (e: any) => { const quality = e.target.getAttribute('data-quality'); - if (quality) { - changeVideoQuality(quality); + const urlParams = new URLSearchParams(window.location.search); + if (quality !== urlParams.get('quality')) { + changeVideoQuality(quality, player); } dropUpMenuElement.style.display = 'none'; }); item.addEventListener('touchend', (e: any) => { const quality = e.target.getAttribute('data-quality'); if (quality) { - changeVideoQuality(quality); + changeVideoQuality(quality, player); } dropUpMenuElement.style.display = 'none'; dropUpMenuElement.style.display = 'none'; diff --git a/src/components/VideoPlayer2.tsx b/src/components/VideoPlayer2.tsx index a1bebf547..b3c008558 100644 --- a/src/components/VideoPlayer2.tsx +++ b/src/components/VideoPlayer2.tsx @@ -15,6 +15,7 @@ import './QualitySelectorControllBar'; // todo correct types interface VideoPlayerProps { + setQuality: React.Dispatch>; options: any; onReady?: (player: Player) => void; subtitles?: string; @@ -26,6 +27,7 @@ const PLAYBACK_RATES: number[] = [0.5, 1, 1.25, 1.5, 1.75, 2]; const VOLUME_LEVELS: number[] = [0, 0.2, 0.4, 0.6, 0.8, 1.0]; export const VideoPlayer: FunctionComponent = ({ + setQuality, options, contentId, onReady, @@ -231,6 +233,7 @@ export const VideoPlayer: FunctionComponent = ({ back: 15, }); + player.qualitySelector = setQuality; const qualitySelector = player.controlBar.addChild( 'QualitySelectorControllBar', ); @@ -266,6 +269,14 @@ export const VideoPlayer: FunctionComponent = ({ } }, [options, onReady]); + useEffect(() => { + if (player) { + const currentTime = player.currentTime(); + player.src(options.sources[0]); + player.currentTime(currentTime); + } + }, [options.sources[0]]); + useEffect(() => { const player = playerRef.current; return () => { diff --git a/src/components/VideoPlayerSegment.tsx b/src/components/VideoPlayerSegment.tsx index 141916f4c..e3dbc4e67 100644 --- a/src/components/VideoPlayerSegment.tsx +++ b/src/components/VideoPlayerSegment.tsx @@ -18,6 +18,7 @@ export interface Thumbnail { } interface VideoProps { + setQuality: React.Dispatch>; thumbnails: Thumbnail[]; segments: Segment[]; subtitles: string; @@ -27,6 +28,7 @@ interface VideoProps { } export const VideoPlayerSegment: FunctionComponent = ({ + setQuality, contentId, subtitles, segments, @@ -93,6 +95,7 @@ export const VideoPlayerSegment: FunctionComponent = ({ className="hidden absolute bg-no-repeat bg-cover w-[320px] h-[180px] pointer-events-none z-10" /> ( + searchParams.get('quality') | null, + ); if (!metadata) { return
Loading
; @@ -92,6 +94,7 @@ export const ContentRendererClient = ({