mirror of
https://github.com/zoriya/react-native-omni.git
synced 2026-08-16 02:44:51 +00:00
fix(cast): fix empty source on rejoin
This commit is contained in:
@@ -466,6 +466,8 @@ class OmniPlayer(
|
|||||||
player.addListener(object : Player.Listener {
|
player.addListener(object : Player.Listener {
|
||||||
override fun onMediaItemTransition(item: MediaItem?, reason: Int) = followMedia(item)
|
override fun onMediaItemTransition(item: MediaItem?, reason: Int) = followMedia(item)
|
||||||
})
|
})
|
||||||
|
// check for cast rejoin
|
||||||
|
followMedia(player.currentMediaItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ function PlayerExample({
|
|||||||
const volume = usePlayerState("volume");
|
const volume = usePlayerState("volume");
|
||||||
const isAutoQuality = usePlayerState("isAutoQuality");
|
const isAutoQuality = usePlayerState("isAutoQuality");
|
||||||
const castStatus = usePlayerState("castStatus");
|
const castStatus = usePlayerState("castStatus");
|
||||||
|
const source = usePlayerState("source");
|
||||||
const [logs, setLogs] = useState<{ id: number; message: string }[]>([]);
|
const [logs, setLogs] = useState<{ id: number; message: string }[]>([]);
|
||||||
const logId = useRef(0);
|
const logId = useRef(0);
|
||||||
const tracks = {
|
const tracks = {
|
||||||
@@ -281,6 +282,9 @@ function PlayerExample({
|
|||||||
<Text style={styles.statText}>
|
<Text style={styles.statText}>
|
||||||
Volume: {(volume * 100).toFixed(0)}%
|
Volume: {(volume * 100).toFixed(0)}%
|
||||||
</Text>
|
</Text>
|
||||||
|
<Text style={styles.statText}>
|
||||||
|
Source: {source?.metadata?.title ?? "(none)"}
|
||||||
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<View style={styles.selectorCard}>
|
<View style={styles.selectorCard}>
|
||||||
|
|||||||
+6
-2
@@ -4,6 +4,7 @@ import {
|
|||||||
useContext,
|
useContext,
|
||||||
useEffect,
|
useEffect,
|
||||||
useEffectEvent,
|
useEffectEvent,
|
||||||
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from "react";
|
} from "react";
|
||||||
import { NitroModules } from "react-native-nitro-modules";
|
import { NitroModules } from "react-native-nitro-modules";
|
||||||
@@ -47,10 +48,13 @@ export const OmniProvider = ({
|
|||||||
return () => player.abandon();
|
return () => player.abandon();
|
||||||
}, [player]);
|
}, [player]);
|
||||||
|
|
||||||
|
const inited = useRef<NativeOmniPlayer | null>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!player) return;
|
if (!player) return;
|
||||||
// early return on init to keep running cast sessions active
|
if (inited.current !== player) {
|
||||||
if (source == null && player.source == null) return;
|
inited.current = player;
|
||||||
|
if (source == null) return;
|
||||||
|
}
|
||||||
player.source = source;
|
player.source = source;
|
||||||
}, [player, source]);
|
}, [player, source]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user