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
+30 -29
View File
@@ -1,22 +1,22 @@
import { useIsFocused } from "@react-navigation/native";
import { BlurView } from "expo-blur";
import moment from "moment";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { Alert, Image, Platform, Text, View } from "react-native";
import Page from "../../layouts/Page";
import { ai, background } from "../../assets";
import MusicLandHeader from "../../components/MusicLandHeader";
import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader";
import { BlurView } from "expo-blur";
import { Palette } from "../../styles";
import ProgressBar from "../../components/ProgressBar";
import GradientButton from "../../components/GradientButton";
import { goBack, navigate } from "../../navigation/NavigationService";
import { Routes } from "../../navigation";
import firebase, { projectsRef } from "../../config/firebase";
import useMinuit from "react-native-minuit/src/hooks/useMinuit.js";
import moment from "moment";
import { responsiveHeight } from "react-native-responsive-dimensions";
import { FONT_FAMILY } from "../../styles/Fonts";
import { ai, background } from "../../assets";
import GradientButton from "../../components/GradientButton";
import MusicLandHeader from "../../components/MusicLandHeader";
import ProgressBar from "../../components/ProgressBar";
import firebase, { projectsRef } from "../../config/firebase";
import Page from "../../layouts/Page";
import { Routes } from "../../navigation";
import { navigate } from "../../navigation/NavigationService";
import { useUser } from "../../providers/UserDataProvider";
import { useIsFocused } from "@react-navigation/native";
import { Palette } from "../../styles";
import { FONT_FAMILY } from "../../styles/Fonts";
import CreateLyricsHeader from "../Writing/components/CreateLyricsHeader";
const GeneratingSong = () => {
const { selectedProjectId, selectedProject } = useUser();
@@ -146,22 +146,23 @@ const GeneratingSong = () => {
if (canAsk && !askedRef.current) {
askedRef.current = true;
Alert.alert(
"Attention",
"Une génération va être lancée. Continuer ?",
[
{
text: "Non",
style: "cancel",
},
{
text: "Oui",
onPress: () => startMusicGeneration(),
},
],
);
Alert.alert("Attention", "Une génération va être lancée. Continuer ?", [
{
text: "Non",
style: "cancel",
},
{
text: "Oui",
onPress: () => startMusicGeneration(),
},
]);
}
}, [isFocused, selectedProject?.title, selectedProject?.musicStatus, effectiveConfig]);
}, [
isFocused,
selectedProject?.title,
selectedProject?.musicStatus,
effectiveConfig,
]);
return (
<Page headerType="NONE" backgroundImg={background.studioBG2}>
+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
);
}
}}