second flow
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
/* global setInterval, clearInterval */
|
||||
import { useFocusEffect } from "@react-navigation/native";
|
||||
import { useAudioPlayer } from "expo-audio";
|
||||
import { BlurView } from "expo-blur";
|
||||
@@ -51,11 +52,18 @@ const SongReady = () => {
|
||||
|
||||
// Sync progression depuis les players
|
||||
useEffect(() => {
|
||||
// expo-audio returns seconds on native, but on web values can be milliseconds
|
||||
const toMs = (t) => {
|
||||
const n = Number(t || 0);
|
||||
if (!isFinite(n) || n <= 0) return 0;
|
||||
return Platform.OS === "web" ? n : n * 1000;
|
||||
};
|
||||
|
||||
const id = setInterval(() => {
|
||||
const d0 = (player0?.duration || 0) * 1000;
|
||||
const p0 = (player0?.currentTime || 0) * 1000;
|
||||
const d1 = (player1?.duration || 0) * 1000;
|
||||
const p1 = (player1?.currentTime || 0) * 1000;
|
||||
const d0 = toMs(player0?.duration);
|
||||
const p0 = toMs(player0?.currentTime);
|
||||
const d1 = toMs(player1?.duration);
|
||||
const p1 = toMs(player1?.currentTime);
|
||||
setProgressInfo({ 0: { pos: p0, dur: d0 }, 1: { pos: p1, dur: d1 } });
|
||||
setIsPlaying({ 0: !!player0?.playing, 1: !!player1?.playing });
|
||||
}, 300);
|
||||
@@ -103,6 +111,7 @@ const SongReady = () => {
|
||||
const pos = Math.floor(dur * ratio);
|
||||
const player = idx === 0 ? player0 : player1;
|
||||
if (player && dur > 0) {
|
||||
// seekTo expects seconds
|
||||
await player.seekTo?.(Math.floor((pos || 0) / 1000));
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user