1import React from 'react'; 2 3import NativeVideoModule from './NativeVideoModule'; 4import NativeVideoView from './NativeVideoView'; 5import { VideoPlayer } from './VideoPlayer'; 6 7export function useVideoPlayer(source: string | null = null): VideoPlayer { 8 return React.useMemo(() => { 9 return new NativeVideoModule.VideoPlayer(source); 10 }, []); 11} 12 13export class VideoView extends React.PureComponent<any> { 14 nativeRef = React.createRef(); 15 16 enterFullscreen() { 17 // @ts-expect-error 18 this.nativeRef.current?.enterFullscreen(); 19 } 20 21 exitFullscreen() { 22 // @ts-expect-error 23 this.nativeRef.current?.exitFullscreen(); 24 } 25 26 render(): React.ReactNode { 27 const { player, ...props } = this.props; 28 const playerId = getPlayerId(player); 29 30 return <NativeVideoView {...props} player={playerId} ref={this.nativeRef} />; 31 } 32} 33 34// Temporary solution to pass the shared object ID instead of the player object. 35// We can't really pass it as an object in the old architecture. 36// Technically we can in the new architecture, but it's not possible yet. 37function getPlayerId(player: number | VideoPlayer): number | null { 38 if (player instanceof NativeVideoModule.VideoPlayer) { 39 // @ts-expect-error 40 return player.__expo_shared_object_id__; 41 } 42 if (typeof player === 'number') { 43 return player; 44 } 45 return null; 46} 47