Skip to content

Commit

Permalink
fix: avoid crash when setting index to 0 to tracks selection (#3721)
Browse files Browse the repository at this point in the history
* fix(ts): onPlaybackRateChangeData was not correctly typed

* fix: ensure tracks are well displayed in the sample

* fix: avoid crash when setting invalid selected track or index 0
freeboub authored Apr 30, 2024
1 parent 1a8295c commit 518a9a9
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/Video.tsx
Original file line number Diff line number Diff line change
@@ -193,27 +193,30 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
if (!selectedTextTrack) {
return;
}
const value = selectedTextTrack.value
? `${selectedTextTrack.value}`
: undefined;

const type = typeof selectedTextTrack.value;
if (type !== 'number' && type !== 'string') {
console.log('invalid type provided to selectedTextTrack');
return;
}
return {
type: selectedTextTrack?.type,
value,
value: `${selectedTextTrack.value}`,
};
}, [selectedTextTrack]);

const _selectedAudioTrack = useMemo(() => {
if (!selectedAudioTrack) {
return;
}
const value = selectedAudioTrack.value
? `${selectedAudioTrack.value}`
: undefined;
const type = typeof selectedAudioTrack.value;
if (type !== 'number' && type !== 'string') {
console.log('invalid type provided to selectedAudioTrack');
return;
}

return {
type: selectedAudioTrack?.type,
value,
value: `${selectedAudioTrack.value}`,
};
}, [selectedAudioTrack]);

0 comments on commit 518a9a9

Please sign in to comment.