Fix error handling on some malformed videos

This commit is contained in:
Zoe Roux 2024-03-24 23:52:41 +01:00
parent f798f2c025
commit 411bbef65c
No known key found for this signature in database
2 changed files with 8 additions and 3 deletions

View File

@ -103,13 +103,18 @@ const Video = forwardRef<VideoRef, VideoProps>(function Video(
onLoad?.(info); onLoad?.(info);
}} }}
onBuffer={onBuffer} onBuffer={onBuffer}
onError={onMediaUnsupported} onError={(error) => {
console.error(error);
if (mode === PlayMode.Direct) onMediaUnsupported?.();
else onError?.(error);
}}
selectedVideoTrack={ selectedVideoTrack={
video === -1 video === -1
? { type: SelectedVideoTrackType.AUDO } ? { type: SelectedVideoTrackType.AUDO }
: { type: SelectedVideoTrackType.RESOLUTION, value: video } : { type: SelectedVideoTrackType.RESOLUTION, value: video }
} }
selectedAudioTrack={{ type: SelectedTrackType.INDEX, value: audio.index }} // when video file is invalid, audio is undefined
selectedAudioTrack={{ type: SelectedTrackType.INDEX, value: audio?.index ?? 0 }}
textTracks={subtitles?.map((x) => ({ textTracks={subtitles?.map((x) => ({
type: MimeTypes.get(x.codec) as any, type: MimeTypes.get(x.codec) as any,
uri: x.link!, uri: x.link!,

View File

@ -182,7 +182,7 @@ const Video = forwardRef<{ seek: (value: number) => void }, VideoProps>(function
if (!hls) return; if (!hls) return;
const update = () => { const update = () => {
if (!hls) return; if (!hls) return;
hls.audioTrack = audio.index; hls.audioTrack = audio?.index ?? 0;
}; };
update(); update();
hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, update); hls.on(Hls.Events.AUDIO_TRACKS_UPDATED, update);