feat: try sync audio to video

This commit is contained in:
2026-01-20 11:16:36 +01:00
parent 4343cee298
commit 490698cb92
5 changed files with 131 additions and 110 deletions
+13 -12
View File
@@ -12,6 +12,7 @@ import Page from '../../layouts/Page'
import { Routes } from '../../navigation'
import { goBack, navigate } from '../../navigation/NavigationService'
import { gutters, Palette } from '../../styles'
import { FONT_FAMILY } from '../../styles/Fonts'
const RecordedPlayback = ({ route }) => {
const { videoUri, project } = route.params || {}
const songUrl = project?.songUrl || null
@@ -40,10 +41,10 @@ const RecordedPlayback = ({ route }) => {
const stopPlayback = useCallback(async () => {
try {
if (audioPlayer?.playing) await audioPlayer.pause?.()
} catch (e) {}
} catch (e) { }
try {
if (videoPlayer?.playing) videoPlayer.pause()
} catch (e) {}
} catch (e) { }
}, [audioPlayer, videoPlayer])
useEffect(() => {
@@ -52,7 +53,7 @@ const RecordedPlayback = ({ route }) => {
try {
if (audioPlayer && songUrl) await audioPlayer.play?.()
if (videoPlayer) videoPlayer.play()
} catch (e) {}
} catch (e) { }
}
start()
return () => {
@@ -78,7 +79,7 @@ const RecordedPlayback = ({ route }) => {
videoPlayer.currentTime = Math.max(0, (pos || 0) / 1000)
}
}
} catch (e) {}
} catch (e) { }
}, 250)
return () => global.clearInterval(id)
}, [audioPlayer, videoPlayer])
@@ -89,7 +90,7 @@ const RecordedPlayback = ({ route }) => {
const pos = Math.max(0, Math.min(dur, Math.floor(targetMs)))
if (audioPlayer && dur > 0) await audioPlayer.seekTo?.(Math.floor(pos / 1000))
if (videoPlayer) videoPlayer.currentTime = Math.max(0, pos / 1000)
} catch (e) {}
} catch (e) { }
}
const onSeekStart = useCallback(() => {
@@ -99,19 +100,19 @@ const RecordedPlayback = ({ route }) => {
const pauseDuringSeek = useCallback(async () => {
try {
if (audioPlayer?.playing) await audioPlayer.pause?.()
} catch (e) {}
} catch (e) { }
try {
if (videoPlayer?.playing) videoPlayer.pause()
} catch (e) {}
} catch (e) { }
}, [audioPlayer, videoPlayer])
const resumeAfterSeek = useCallback(async () => {
try {
if (audioPlayer) await audioPlayer.play?.()
} catch (e) {}
} catch (e) { }
try {
if (videoPlayer) videoPlayer.play()
} catch (e) {}
} catch (e) { }
}, [audioPlayer, videoPlayer])
const sliderProgress = useMemo(() => {
@@ -155,7 +156,7 @@ const RecordedPlayback = ({ route }) => {
playbackEndedRef.current = false
if (songUrl && audioPlayer) await audioPlayer.play?.()
if (videoPlayer) videoPlayer.play()
} catch (e) {}
} catch (e) { }
}
return (
@@ -225,7 +226,7 @@ const RecordedPlayback = ({ route }) => {
onPress={async () => {
try {
await stopPlayback()
} catch (e) {}
} catch (e) { }
try {
if (videoUri) {
const info = await FileSystem.getInfoAsync(videoUri)
@@ -234,7 +235,7 @@ const RecordedPlayback = ({ route }) => {
idempotent: true,
})
}
} catch (e) {}
} catch (e) { }
navigate(Routes.RecordPlayback, { project })
}}
/>