import React, { forwardRef, memo, useCallback, type Dispatch, type SetStateAction, } from 'react'; import {Indicator} from './Indicator.tsx'; import {View} from 'react-native'; import styles from '../styles.tsx'; import ToggleControl from '../ToggleControl.tsx'; import { isAndroid, isIos, samplePoster, textTracksSelectionBy, } from '../constants'; import MultiValueControl, { type MultiValueControlPropType, } from '../MultiValueControl.tsx'; import { ResizeMode, VideoRef, SelectedTrackType, SelectedVideoTrackType, VideoDecoderProperties, type EnumValues, type TextTrack, type SelectedVideoTrack, type SelectedTrack, type VideoTrack, type AudioTrack, } from 'react-native-video'; import { toast, Seeker, AudioTrackSelector, TextTrackSelector, VideoTrackSelector, TopControl, } from '../components'; type Props = { channelDown: () => void; channelUp: () => void; setFullscreen: Dispatch>; controls: boolean; setControls: Dispatch>; showNotificationControls: boolean; setShowNotificationControls: Dispatch>; selectedAudioTrack: SelectedTrack | undefined; setSelectedAudioTrack: Dispatch>; selectedTextTrack: SelectedTrack | undefined; setSelectedTextTrack: (value: SelectedTrack | undefined) => void; selectedVideoTrack: SelectedVideoTrack; setSelectedVideoTrack: (value: SelectedVideoTrack) => void; setIsSeeking: Dispatch>; rate: number; setRate: Dispatch>; volume: number; setVolume: (value: number) => void; resizeMode: EnumValues; setResizeMode: Dispatch>>; isLoading: boolean; srcListId: number; useCache: boolean; setUseCache: Dispatch>; paused: boolean; setPaused: Dispatch>; repeat: boolean; setRepeat: Dispatch>; poster: string | undefined; setPoster: Dispatch>; muted: boolean; setMuted: Dispatch>; currentTime: number; duration: number; isSeeking: boolean; audioTracks: AudioTrack[]; textTracks: TextTrack[]; videoTracks: VideoTrack[]; }; const _Overlay = forwardRef((props, ref) => { const { channelUp, channelDown, setFullscreen, setControls, controls, setShowNotificationControls, showNotificationControls, setSelectedAudioTrack, setSelectedTextTrack, setSelectedVideoTrack, setIsSeeking, rate, setRate, volume, setVolume, resizeMode, setResizeMode, isLoading, srcListId, setUseCache, useCache, paused, setPaused, setRepeat, repeat, setPoster, poster, setMuted, muted, duration, isSeeking, currentTime, textTracks, videoTracks, audioTracks, selectedAudioTrack, selectedVideoTrack, selectedTextTrack, } = props; const popupInfo = useCallback(() => { VideoDecoderProperties.getWidevineLevel().then((widevineLevel: number) => { VideoDecoderProperties.isHEVCSupported().then((hevc: string) => { VideoDecoderProperties.isCodecSupported('video/avc', 1920, 1080).then( (avc: string) => { toast( true, 'Widevine level: ' + widevineLevel + '\n hevc: ' + hevc + '\n avc: ' + avc, ); }, ); }); }); }, []); const toggleFullscreen = () => { setFullscreen(prev => !prev); }; const toggleControls = () => { setControls(prev => !prev); }; const openDecoration = () => { typeof ref !== 'function' && ref?.current?.setFullScreen(true); }; const toggleShowNotificationControls = () => { setShowNotificationControls(prev => !prev); }; const onSelectedAudioTrackChange = (itemValue: string) => { console.log('on audio value change ' + itemValue); if (itemValue === 'none') { setSelectedAudioTrack({ type: SelectedTrackType.DISABLED, }); } else { setSelectedAudioTrack({ type: SelectedTrackType.INDEX, value: itemValue, }); } }; const onSelectedTextTrackChange = (itemValue: string) => { console.log('on value change ' + itemValue); const type = textTracksSelectionBy === 'index' ? SelectedTrackType.INDEX : SelectedTrackType.LANGUAGE; setSelectedTextTrack({type, value: itemValue}); }; const onSelectedVideoTrackChange = (itemValue: string) => { console.log('on value change ' + itemValue); if (itemValue === undefined || itemValue === 'auto') { setSelectedVideoTrack({ type: SelectedVideoTrackType.AUTO, }); } else { setSelectedVideoTrack({ type: SelectedVideoTrackType.INDEX, value: itemValue, }); } }; const videoSeek = (position: number) => { setIsSeeking(true); typeof ref !== 'function' && ref?.current?.seek(position); }; const onRateSelected = (value: number) => { setRate(value); }; const onVolumeSelected = (value: number) => { setVolume(value); }; const onResizeModeSelected = (value: EnumValues) => { setResizeMode(value); }; const toggleCache = () => setUseCache(prev => !prev); const togglePause = () => setPaused(prev => !prev); const toggleRepeat = () => setRepeat(prev => !prev); const togglePoster = () => setPoster(prev => (prev ? undefined : samplePoster)); const toggleMuted = () => setMuted(prev => !prev); return ( <> {!controls ? ( <> {isAndroid ? ( ) : null} {/* shall be replaced by slider */} {/* shall be replaced by slider */} {isIos ? ( { typeof ref !== 'function' && ref?.current ?.save({}) ?.then((response: unknown) => { console.log('Downloaded URI', response); }) .catch((error: unknown) => { console.log('error during save ', error); }); }} text="save" /> ) : null} videoSeek(prop)} isUISeeking={isSeeking} /> ) : null} ); }); export const Overlay = memo(_Overlay);