feat(tv): update video player to handle ended event and improve channel navigation

This commit is contained in:
2026-03-12 04:19:56 +01:00
parent 8754758254
commit 79ced7b77b
4 changed files with 57 additions and 23 deletions

View File

@@ -20,6 +20,8 @@ interface VideoPlayerProps {
onSubtitleTracksChange?: (tracks: SubtitleTrack[]) => void;
/** Called when the browser blocks autoplay and user interaction is required. */
onNeedsInteraction?: () => void;
/** Called when the video element fires its ended event. */
onEnded?: () => void;
}
const VideoPlayer = forwardRef<HTMLVideoElement, VideoPlayerProps>(
@@ -33,12 +35,15 @@ const VideoPlayer = forwardRef<HTMLVideoElement, VideoPlayerProps>(
onStreamError,
onSubtitleTracksChange,
onNeedsInteraction,
onEnded,
},
ref,
) => {
const internalRef = useRef<HTMLVideoElement | null>(null);
const hlsRef = useRef<Hls | null>(null);
const [isBuffering, setIsBuffering] = useState(true);
const onEndedRef = useRef(onEnded);
onEndedRef.current = onEnded;
const setRef = (el: HTMLVideoElement | null) => {
internalRef.current = el;
@@ -126,6 +131,7 @@ const VideoPlayer = forwardRef<HTMLVideoElement, VideoPlayerProps>(
onPlaying={() => setIsBuffering(false)}
onWaiting={() => setIsBuffering(true)}
onError={onStreamError}
onEnded={() => onEndedRef.current?.()}
className="h-full w-full object-contain"
/>