lypsync & other

This commit is contained in:
2026-02-12 15:46:44 +01:00
parent e11ac93ff0
commit acfc7a8394
6 changed files with 77 additions and 19 deletions
+19 -4
View File
@@ -22,6 +22,8 @@ import CreateLyricsHeader from '../Writing/components/CreateLyricsHeader'
const TIME_BEFORE_INCREMENT_MS = 20000 // 20s
const COUNTDOWN_SECONDS = 10
const CAMERA_STARTUP_DELAY_MS = 250
const MAX_SYNC_OFFSET_MS = 2000
const LOG_PREFIX = '[RecordPlayback]'
const KEEP_AWAKE_TAG = 'record-playback'
const log =
@@ -60,6 +62,7 @@ const RecordPlayback = ({ route }) => {
const startedRef = useRef(false) // empêche les doubles démarrages
const countdownActiveRef = useRef(false) // évite le déclenchement avant 1er tick
const playbackStartedRef = useRef(false) // devient vrai lorsque l'audio progresse réellement
const playbackStartedAtRef = useRef(0)
const progressLogRef = useRef({ bucket: -1, lastPos: -1, lastDur: -1 })
const originalLoopingValueRef = useRef({ hasValue: false, value: false })
const latestLoopingValueRef = useRef(isLooping ?? false)
@@ -189,6 +192,7 @@ const RecordPlayback = ({ route }) => {
incrementDoneRef.current = false
progressLogRef.current = { bucket: -1, lastPos: -1, lastDur: -1 }
playbackStartedRef.current = false
playbackStartedAtRef.current = 0
log('Song URL changed, reset counters', { songUrl })
}, [songUrl])
@@ -201,7 +205,10 @@ const RecordPlayback = ({ route }) => {
const pos = (player?.currentTime || 0) * 1000
if (!playbackStartedRef.current && (player?.playing || pos > 0)) {
playbackStartedRef.current = true
log('Playback detected', { pos, dur })
const now = Date.now()
const estimatedStartAt = pos > 0 ? now - pos : now
playbackStartedAtRef.current = estimatedStartAt
log('Playback detected', { pos, dur, startedAt: estimatedStartAt })
}
setProgressInfo((prev) => {
if (prev.pos === pos && prev.dur === dur) return prev
@@ -308,6 +315,7 @@ const RecordPlayback = ({ route }) => {
listenedMsRef.current = 0
incrementDoneRef.current = false
playbackStartedRef.current = false
playbackStartedAtRef.current = 0
progressLogRef.current = { bucket: -1, lastPos: -1, lastDur: -1 }
log('Session reset')
@@ -544,7 +552,7 @@ const RecordPlayback = ({ route }) => {
}
// Add artificial delay to compensate for camera startup latency (Audio usually starts faster than video recording)
await new Promise(r => setTimeout(r, 250))
await new Promise(r => setTimeout(r, CAMERA_STARTUP_DELAY_MS))
try {
await player.play?.()
@@ -698,16 +706,23 @@ const RecordPlayback = ({ route }) => {
return
}
const rawOffsetMs =
playbackStartedAtRef.current && recordingStartTimeRef.current
? playbackStartedAtRef.current - recordingStartTimeRef.current
: 0
const syncOffsetMs = Math.max(0, Math.min(MAX_SYNC_OFFSET_MS, Math.round(rawOffsetMs || 0)))
log('Computed sync offset', { rawOffsetMs, syncOffsetMs })
if (video?.uri) {
log('Navigating to RecordedPlayback with video', {
uriLength: video.uri.length,
})
navigate(Routes.RecordedPlayback, { videoUri: video.uri, project })
navigate(Routes.RecordedPlayback, { videoUri: video.uri, project, syncOffsetMs })
} else {
log('Navigating to RecordedPlayback without video', {
hasVideo: !!video,
})
navigate(Routes.RecordedPlayback, { project })
navigate(Routes.RecordedPlayback, { project, syncOffsetMs })
}
} catch (e) {
log('startRecordingWithMusic error', {