second flow

This commit is contained in:
2025-10-01 16:49:12 +02:00
parent efc84ce2ab
commit 1fd63c254d
8 changed files with 505 additions and 65 deletions
+13 -4
View File
@@ -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) {