show toast when subtitles track loaded

This commit is contained in:
nklhrstv 2020-03-24 13:59:18 +02:00
parent b82cd8e452
commit 8a4825e1a2
2 changed files with 16 additions and 0 deletions

View file

@ -92,6 +92,14 @@ const Player = ({ urlParams }) => {
});
}
}, []);
const onSubtitlesTrackLoaded = React.useCallback((track) => {
toast.show({
type: 'success',
title: 'Subtitles loaded',
message: `Subtitles from ${track.origin} loaded`,
timeout: 4000
});
}, []);
const onPlayRequested = React.useCallback(() => {
dispatch({ propName: 'paused', propValue: false });
}, []);
@ -317,6 +325,7 @@ const Player = ({ urlParams }) => {
onError={onError}
onPropValue={onPropChanged}
onPropChanged={onPropChanged}
onSubtitlesTrackLoaded={onSubtitlesTrackLoaded}
onImplementationChanged={onImplementationChanged}
/>
{

View file

@ -9,6 +9,7 @@ const Video = React.forwardRef(({ className, ...props }, ref) => {
const onErrorRef = useLiveRef(props.onError);
const onPropValueRef = useLiveRef(props.onPropValue);
const onPropChangedRef = useLiveRef(props.onPropChanged);
const onSubtitlesTrackLoadedRef = useLiveRef(props.onSubtitlesTrackLoaded);
const onImplementationChangedRef = useLiveRef(props.onImplementationChanged);
const containerElementRef = React.useRef(null);
const videoRef = React.useRef(null);
@ -45,6 +46,11 @@ const Video = React.forwardRef(({ className, ...props }, ref) => {
onPropChangedRef.current(propName, propValue);
}
});
videoRef.current.on('subtitlesTrackLoaded', (track) => {
if (typeof onSubtitlesTrackLoadedRef.current === 'function') {
onSubtitlesTrackLoadedRef.current(track);
}
});
if (typeof onImplementationChangedRef.current === 'function') {
onImplementationChangedRef.current(videoRef.current.constructor.manifest);
}
@ -79,6 +85,7 @@ Video.propTypes = {
onError: PropTypes.func,
onPropValue: PropTypes.func,
onPropChanged: PropTypes.func,
onSubtitlesTrackLoaded: PropTypes.func,
onImplementationChanged: PropTypes.func
};