music timestamps

This commit is contained in:
2025-09-05 12:20:33 +02:00
parent dd19172804
commit fdd667f092
4 changed files with 77 additions and 94 deletions
+28 -7
View File
@@ -1,6 +1,7 @@
import { useFocusEffect } from "@react-navigation/native";
import { useAudioPlayer } from "expo-audio";
import { BlurView } from "expo-blur";
import React, { useEffect, useRef, useState, useCallback } from "react";
import React, { useCallback, useEffect, useRef, useState } from "react";
import { Image, Platform, Pressable, Text, View } from "react-native";
import { responsiveHeight } from "react-native-responsive-dimensions";
import { background, icons } from "../../assets";
@@ -10,14 +11,13 @@ import ValidateModal from "../../components/modal/ValidateModal";
import MusicLandHeader from "../../components/MusicLandHeader";
import Slider from "../../components/Slider";
import firebase from "../../config/firebase";
import { useUser } from "../../providers/UserDataProvider";
import Page from "../../layouts/Page";
import { Routes } from "../../navigation";
import { navigate } from "../../navigation/NavigationService";
import { useUser } from "../../providers/UserDataProvider";
import { Style } from "../../styles";
import { gutters, size } from "../../styles/Style";
import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader";
import { useFocusEffect } from "@react-navigation/native";
const SongReady = () => {
const {
@@ -34,10 +34,10 @@ const SongReady = () => {
1: { pos: 0, dur: 0 },
});
const player0 = useAudioPlayer(
musicUrls[0] ? { uri: musicUrls[0] } : undefined,
musicUrls[0] ? { uri: musicUrls[0] } : undefined
);
const player1 = useAudioPlayer(
musicUrls[1] ? { uri: musicUrls[1] } : undefined,
musicUrls[1] ? { uri: musicUrls[1] } : undefined
);
const wasPlayingBeforeSeek = useRef({ 0: false, 1: false });
@@ -113,12 +113,33 @@ const SongReady = () => {
const validateSelection = async () => {
try {
const url = musicUrls[selectedIndex];
if (!projectId || !url) return;
await updateProjectData({
songIndex: selectedIndex,
songUrl: url,
updatedAt: firebase.firestore.FieldValue.serverTimestamp(),
});
// Déclenche la génération des timestamps immédiatement après avoir fixé la songUrl
try {
console.log("task id is : ", selectedProject?.sunoTaskId);
const taskId = selectedProject?.sunoTaskId || null;
if (taskId) {
const callable = firebase
.functions()
.httpsCallable("music-getSunoTimestamps");
// Fire-and-forget (ne bloque pas l'UI)
callable({
taskId,
musicIndex: Number(selectedIndex) || 0,
projectId,
}).catch((e) =>
console.log("getSunoTimestamps (non-blocking)", e?.message)
);
}
} catch (e) {
console.log("getSunoTimestamps init error", e?.message);
}
await player0?.pause?.();
await player1?.pause?.();
navigate(Routes.FlowSelection);
@@ -136,7 +157,7 @@ const SongReady = () => {
player1?.pause?.();
} catch {}
};
}, [player0, player1]),
}, [player0, player1])
);
useEffect(() => {
@@ -220,7 +241,7 @@ const SongReady = () => {
} catch (e) {
console.log(
"SongReady pause on seek start",
e?.message,
e?.message
);
}
}}