I am writing player UI in react-native with expo. There is a 3rd party library expo-av
. And in examples section of that lib, react component initialize instance of mediaObject
in useEffect
and saves reference to it in ref (useRef
). And handle events from mediaObject directly in react component via mediaObjectRef.setOnPlaybackStatusUpdate = status => {}
I wrote a Class Media
, that wraps mediaObject
and put there all logic about playing. And also on init() i pass react players' setState hook to this class. And there from onPlaybackStatusUpdate method I update react UI component. Is it normal? I can't find about this approach in google.
I avoid to put this logic to component, because I need to extend my Media class into MediaAdvanced with more logic, and rewrite there event handlers.