mirror of
https://github.com/zoriya/react-native-video.git
synced 2026-06-03 03:11:47 +00:00
fix(web): fix container warning and store lifecycle
This commit is contained in:
@@ -61,6 +61,11 @@ class VideoPlayer extends VideoPlayerEvents implements VideoPlayerBase {
|
|||||||
this.mediaSession?.disable();
|
this.mediaSession?.disable();
|
||||||
(this.eventEmitter as WebEventEmitter).destroy();
|
(this.eventEmitter as WebEventEmitter).destroy();
|
||||||
this.clearAllEvents();
|
this.clearAllEvents();
|
||||||
|
// Store destroy calls detach internally — safe here since player is dead
|
||||||
|
if (this._store?.destroyed === false) {
|
||||||
|
this._store.destroy();
|
||||||
|
}
|
||||||
|
this._store = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
|||||||
@@ -21,13 +21,15 @@ const Player = createPlayer({ features: videoFeatures });
|
|||||||
* then passes the ready store to the adapter.
|
* then passes the ready store to the adapter.
|
||||||
*/
|
*/
|
||||||
function PlayerBridge({ player }: { player: VideoPlayer }) {
|
function PlayerBridge({ player }: { player: VideoPlayer }) {
|
||||||
const { store } = usePlayerContext();
|
const { store, container } = usePlayerContext();
|
||||||
const setMedia = useMediaAttach();
|
const setMedia = useMediaAttach();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
const video = player.__getMedia();
|
const video = player.__getMedia();
|
||||||
setMedia?.(video);
|
setMedia?.(video);
|
||||||
const detach = store.attach({ media: video, container: null });
|
const detach = store.attach({ media: video, container });
|
||||||
player.__setStore(store);
|
player.__setStore(store);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
@@ -35,7 +37,7 @@ function PlayerBridge({ player }: { player: VideoPlayer }) {
|
|||||||
detach?.();
|
detach?.();
|
||||||
setMedia?.(null);
|
setMedia?.(null);
|
||||||
};
|
};
|
||||||
}, [store, player, setMedia]);
|
}, [store, player, setMedia, container]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user