@@ -4,6 +4,7 @@ import { VideoPlayerAdapter, VideoPlayerProps, VideoPlayerRef, VideoPlayerType }
44export class ExpoVideoAdapter implements VideoPlayerAdapter {
55 private expoVideoModule : any = null ;
66 private videoPlayer : any = null ;
7+ private eventListeners : any [ ] = [ ] ;
78
89 constructor ( ) {
910 this . loadExpoVideo ( ) ;
@@ -35,49 +36,79 @@ export class ExpoVideoAdapter implements VideoPlayerAdapter {
3536 throw new Error ( 'expo-video is not available' ) ;
3637 }
3738
39+ console . log ( 'ExpoVideoAdapter - Rendering video:' , {
40+ videoUri : props . videoUri ,
41+ hasOnPlaybackStatusUpdate : ! ! props . onPlaybackStatusUpdate
42+ } ) ;
43+
3844 const { VideoView, createVideoPlayer } = this . expoVideoModule ;
3945
4046 // Create or reuse the video player
4147 if ( ! this . videoPlayer ) {
48+ console . log ( 'ExpoVideoAdapter - Creating new video player' ) ;
4249 this . videoPlayer = createVideoPlayer ( props . videoUri ) ;
50+
51+ // Set up player event listeners for expo-video
52+ if ( this . videoPlayer && props . onPlaybackStatusUpdate ) {
53+ // Clear any existing listeners
54+ this . cleanup ( ) ;
55+
56+ // Try different event names that might exist in expo-video
57+ const statusListener = this . videoPlayer . addListener ?.( 'statusChange' , ( status : any ) => {
58+ console . log ( 'ExpoVideoAdapter - Player status change:' , status ) ;
59+ // Convert expo-video status to expo-av-like status format
60+ const normalizedStatus = {
61+ isLoaded : status . status === 'loaded' || status . status === 'readyToPlay' ,
62+ isPlaying : status . status === 'playing' ,
63+ positionMillis : ( status . currentTime || 0 ) * 1000 ,
64+ durationMillis : ( status . duration || 0 ) * 1000 ,
65+ isMuted : status . isMuted || false ,
66+ error : status . error ,
67+ ...status
68+ } ;
69+ this . processExpoVideoEvents ( ref . current , 'onPlaybackStatusUpdate' , normalizedStatus ) ;
70+ props . onPlaybackStatusUpdate ?.( normalizedStatus ) ;
71+ } ) ;
72+
73+ if ( statusListener ) {
74+ this . eventListeners . push ( statusListener ) ;
75+ }
76+
77+ // Try alternative event names
78+ const playbackListener = this . videoPlayer . addListener ?.( 'playbackStatusUpdate' , ( status : any ) => {
79+ console . log ( 'ExpoVideoAdapter - Playback status update:' , status ) ;
80+ props . onPlaybackStatusUpdate ?.( status ) ;
81+ } ) ;
82+
83+ if ( playbackListener ) {
84+ this . eventListeners . push ( playbackListener ) ;
85+ }
86+
87+ // Simulate initial status for immediate feedback
88+ setTimeout ( ( ) => {
89+ const initialStatus = {
90+ isLoaded : false ,
91+ isPlaying : false ,
92+ positionMillis : 0 ,
93+ durationMillis : 0 ,
94+ isMuted : false ,
95+ } ;
96+ console . log ( 'ExpoVideoAdapter - Sending initial status' ) ;
97+ props . onPlaybackStatusUpdate ?.( initialStatus ) ;
98+ } , 100 ) ;
99+ }
43100 } else {
44101 // Update the source if it changed
102+ console . log ( 'ExpoVideoAdapter - Updating video source' ) ;
45103 this . videoPlayer . source = props . videoUri ;
46104 }
47105
48106 return React . createElement ( VideoView , {
49107 ref,
50108 player : this . videoPlayer ,
51109 style : props . style ,
52- nativeControls : true ,
53- onPlaybackStatusUpdate : ( status : any ) => {
54- this . processExpoVideoEvents ( ref . current , 'onPlaybackStatusUpdate' , status ) ;
55- props . onPlaybackStatusUpdate ?.( status ) ;
56- } ,
57- onLoadStart : ( data : any ) => {
58- this . processExpoVideoEvents ( ref . current , 'onLoadStart' , data ) ;
59- props . onLoadStart ?.( data ) ;
60- } ,
61- onLoad : ( data : any ) => {
62- this . processExpoVideoEvents ( ref . current , 'onLoad' , data ) ;
63- props . onLoad ?.( data ) ;
64- } ,
65- onError : ( error : any ) => {
66- this . processExpoVideoEvents ( ref . current , 'onError' , error ) ;
67- props . onError ?.( error ) ;
68- } ,
69- onReadyForDisplay : ( data : any ) => {
70- this . processExpoVideoEvents ( ref . current , 'onReadyForDisplay' , data ) ;
71- props . onReadyForDisplay ?.( data ) ;
72- } ,
73- onPlayingChange : ( isPlaying : boolean ) => {
74- this . processExpoVideoEvents ( ref . current , 'onPlayingChange' , isPlaying ) ;
75- props . onPlayingChange ?.( isPlaying ) ;
76- } ,
77- onEnd : ( data : any ) => {
78- this . processExpoVideoEvents ( ref . current , 'onEnd' , data ) ;
79- props . onEnd ?.( data ) ;
80- } ,
110+ nativeControls : false ,
111+ // Note: expo-video uses player event listeners instead of VideoView props for status updates
81112 } ) ;
82113 }
83114
@@ -110,6 +141,13 @@ export class ExpoVideoAdapter implements VideoPlayerAdapter {
110141 }
111142
112143 cleanup ( ) : void {
144+ // Remove all event listeners
145+ this . eventListeners . forEach ( listener => {
146+ if ( listener && typeof listener . remove === 'function' ) {
147+ listener . remove ( ) ;
148+ }
149+ } ) ;
150+ this . eventListeners = [ ] ;
113151 this . videoPlayer = null ;
114152 }
115153}
0 commit comments