feat(video-player): add muted prop to VideoPlayer and handle mute state in playback
This commit is contained in:
@@ -16,6 +16,7 @@ interface VideoPlayerProps {
|
|||||||
initialOffset?: number;
|
initialOffset?: number;
|
||||||
/** Active subtitle track index, or -1 to disable. */
|
/** Active subtitle track index, or -1 to disable. */
|
||||||
subtitleTrack?: number;
|
subtitleTrack?: number;
|
||||||
|
muted?: boolean;
|
||||||
onStreamError?: () => void;
|
onStreamError?: () => void;
|
||||||
onSubtitleTracksChange?: (tracks: SubtitleTrack[]) => void;
|
onSubtitleTracksChange?: (tracks: SubtitleTrack[]) => void;
|
||||||
/** Called when the browser blocks autoplay and user interaction is required. */
|
/** Called when the browser blocks autoplay and user interaction is required. */
|
||||||
@@ -32,6 +33,7 @@ const VideoPlayer = forwardRef<HTMLVideoElement, VideoPlayerProps>(
|
|||||||
className,
|
className,
|
||||||
initialOffset = 0,
|
initialOffset = 0,
|
||||||
subtitleTrack = -1,
|
subtitleTrack = -1,
|
||||||
|
muted = false,
|
||||||
onStreamError,
|
onStreamError,
|
||||||
onSubtitleTracksChange,
|
onSubtitleTracksChange,
|
||||||
onNeedsInteraction,
|
onNeedsInteraction,
|
||||||
@@ -44,6 +46,12 @@ const VideoPlayer = forwardRef<HTMLVideoElement, VideoPlayerProps>(
|
|||||||
const [isBuffering, setIsBuffering] = useState(true);
|
const [isBuffering, setIsBuffering] = useState(true);
|
||||||
const onEndedRef = useRef(onEnded);
|
const onEndedRef = useRef(onEnded);
|
||||||
onEndedRef.current = onEnded;
|
onEndedRef.current = onEnded;
|
||||||
|
const mutedRef = useRef(muted);
|
||||||
|
mutedRef.current = muted;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (internalRef.current) internalRef.current.muted = muted;
|
||||||
|
}, [muted]);
|
||||||
|
|
||||||
const setRef = (el: HTMLVideoElement | null) => {
|
const setRef = (el: HTMLVideoElement | null) => {
|
||||||
internalRef.current = el;
|
internalRef.current = el;
|
||||||
@@ -77,6 +85,7 @@ const VideoPlayer = forwardRef<HTMLVideoElement, VideoPlayerProps>(
|
|||||||
hlsRef.current = hls;
|
hlsRef.current = hls;
|
||||||
|
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
||||||
|
video.muted = mutedRef.current;
|
||||||
video.play().catch(() => onNeedsInteraction?.());
|
video.play().catch(() => onNeedsInteraction?.());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -482,6 +482,7 @@ function TvPageContent() {
|
|||||||
className="absolute inset-0 h-full w-full"
|
className="absolute inset-0 h-full w-full"
|
||||||
initialOffset={broadcast ? calcOffsetSecs(broadcast.slot.start_at) : 0}
|
initialOffset={broadcast ? calcOffsetSecs(broadcast.slot.start_at) : 0}
|
||||||
subtitleTrack={activeSubtitleTrack}
|
subtitleTrack={activeSubtitleTrack}
|
||||||
|
muted={isMuted}
|
||||||
onSubtitleTracksChange={setSubtitleTracks}
|
onSubtitleTracksChange={setSubtitleTracks}
|
||||||
onStreamError={handleStreamError}
|
onStreamError={handleStreamError}
|
||||||
onEnded={handleVideoEnded}
|
onEnded={handleVideoEnded}
|
||||||
|
|||||||
Reference in New Issue
Block a user