Accessing the native Player instance
When you instantiate a player with usePlayer
or new Player()
from javascript, you are actually either creating a new Player
instance on the native side (see SDKs docs for more info), or referencing an existing one.
This means that Player
instances with the same nativeId
in different parts of the code are referencing the same in-memory instance internally.
Example
Both components in the example below are referencing the same native Player
, indexed as my-player
. And even though each <PlayerView />
creates a different View internally, the underlying Player instance remains the same. It just gets attached to a different view.
// Using `usePlayer`
export const CompA = () => {
// Same `player` as in `CompB`.
const player = usePlayer({
nativeId: 'my-player',
});
return <PlayerView player={player} />;
};
// Using `new Player()`
export const CompB = () => {
// Same `player` as in `CompA`.
const player = useRef(
new Player({
nativeId: 'my-player',
})
);
return <PlayerView player={player.current} />;
};
Updated 11 months ago