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);
}}
onBuffer={onBuffer}
onError={onMediaUnsupported}
onError={(error) => {
console.error(error);
if (mode === PlayMode.Direct) onMediaUnsupported?.();
else onError?.(error);
}}
selectedVideoTrack={
video === -1
? { type: SelectedVideoTrackType.AUDO }
: { 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) => ({
type: MimeTypes.get(x.codec) as any,
uri: x.link!,

View File

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