stop audio & go back to home
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { useFocusEffect } from '@react-navigation/native'
|
||||||
import useSharedAudioPlayer from '../../hooks/useSharedAudioPlayer'
|
import useSharedAudioPlayer from '../../hooks/useSharedAudioPlayer'
|
||||||
import * as FileSystem from 'expo-file-system'
|
import * as FileSystem from 'expo-file-system'
|
||||||
import { VideoView, useVideoPlayer } from 'expo-video'
|
import { VideoView, useVideoPlayer } from 'expo-video'
|
||||||
@@ -40,13 +41,21 @@ const RecordedPlayback = ({ route }) => {
|
|||||||
// Start both players on mount
|
// Start both players on mount
|
||||||
const stopPlayback = useCallback(async () => {
|
const stopPlayback = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
if (audioPlayer?.playing) await audioPlayer.pause?.()
|
if (audioPlayer) await audioPlayer.pause?.()
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
try {
|
try {
|
||||||
if (videoPlayer?.playing) videoPlayer.pause()
|
videoPlayer?.pause?.()
|
||||||
} catch (e) { }
|
} catch (e) { }
|
||||||
}, [audioPlayer, videoPlayer])
|
}, [audioPlayer, videoPlayer])
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
return () => {
|
||||||
|
void stopPlayback()
|
||||||
|
}
|
||||||
|
}, [stopPlayback])
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
playbackEndedRef.current = false
|
playbackEndedRef.current = false
|
||||||
const start = async () => {
|
const start = async () => {
|
||||||
@@ -213,7 +222,10 @@ const RecordedPlayback = ({ route }) => {
|
|||||||
<View style={{ width: '80%', alignSelf: 'center', marginTop: 4, gap: 12 }}>
|
<View style={{ width: '80%', alignSelf: 'center', marginTop: 4, gap: 12 }}>
|
||||||
<GradientButton
|
<GradientButton
|
||||||
title="Je valide"
|
title="Je valide"
|
||||||
onPress={() => {
|
onPress={async () => {
|
||||||
|
try {
|
||||||
|
await stopPlayback()
|
||||||
|
} catch (e) { }
|
||||||
navigate(Routes.PlaybackDownload, {
|
navigate(Routes.PlaybackDownload, {
|
||||||
action: 'playback',
|
action: 'playback',
|
||||||
uri: videoUri,
|
uri: videoUri,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useFocusEffect } from '@react-navigation/native'
|
||||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||||||
import { Image, Pressable, Text, View } from 'react-native'
|
import { Image, Pressable, Text, View } from 'react-native'
|
||||||
import { background, icons } from '../../assets'
|
import { background, icons } from '../../assets'
|
||||||
@@ -54,7 +55,7 @@ const RecordedPlayback = ({ route }) => {
|
|||||||
|
|
||||||
const stopPlayback = useCallback(async () => {
|
const stopPlayback = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
if (audioPlayer?.playing) await audioPlayer.pause?.()
|
if (audioPlayer) await audioPlayer.pause?.()
|
||||||
} catch { }
|
} catch { }
|
||||||
try {
|
try {
|
||||||
if (videoElRef.current && !videoElRef.current.paused) {
|
if (videoElRef.current && !videoElRef.current.paused) {
|
||||||
@@ -63,6 +64,14 @@ const RecordedPlayback = ({ route }) => {
|
|||||||
} catch { }
|
} catch { }
|
||||||
}, [audioPlayer])
|
}, [audioPlayer])
|
||||||
|
|
||||||
|
useFocusEffect(
|
||||||
|
useCallback(() => {
|
||||||
|
return () => {
|
||||||
|
void stopPlayback()
|
||||||
|
}
|
||||||
|
}, [stopPlayback])
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
if (!shouldPreserveBlobRef.current) {
|
if (!shouldPreserveBlobRef.current) {
|
||||||
@@ -363,8 +372,11 @@ const RecordedPlayback = ({ route }) => {
|
|||||||
>
|
>
|
||||||
<GradientButton
|
<GradientButton
|
||||||
title="Je valide"
|
title="Je valide"
|
||||||
onPress={() => {
|
onPress={async () => {
|
||||||
shouldPreserveBlobRef.current = true
|
shouldPreserveBlobRef.current = true
|
||||||
|
try {
|
||||||
|
await stopPlayback()
|
||||||
|
} catch { }
|
||||||
navigate(Routes.PlaybackDownload, {
|
navigate(Routes.PlaybackDownload, {
|
||||||
action: 'playback',
|
action: 'playback',
|
||||||
uri: videoUri || null, // peut être null sur web
|
uri: videoUri || null, // peut être null sur web
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ const PlaybackDownload = ({ route }) => {
|
|||||||
const [isDownloading, setIsDownloading] = useState(false)
|
const [isDownloading, setIsDownloading] = useState(false)
|
||||||
const [hasAcceptedPublication, setHasAcceptedPublication] = useState(true)
|
const [hasAcceptedPublication, setHasAcceptedPublication] = useState(true)
|
||||||
const hasShownAfterPlaybackRef = useRef(false)
|
const hasShownAfterPlaybackRef = useRef(false)
|
||||||
|
const publishSuccessMessage = action === 'playback' ? 'Playback publié !' : 'Chanson publiée !'
|
||||||
|
|
||||||
const afterPlaybackUrl = useMemo(() => {
|
const afterPlaybackUrl = useMemo(() => {
|
||||||
if (!videos) return null
|
if (!videos) return null
|
||||||
@@ -333,15 +334,11 @@ const PlaybackDownload = ({ route }) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!project?.id) {
|
if (!project?.id) {
|
||||||
if (action === 'playback') {
|
setTooltip({
|
||||||
setTooltip({
|
type: 'success',
|
||||||
type: 'success',
|
text: publishSuccessMessage,
|
||||||
text: 'Playback publié !',
|
})
|
||||||
})
|
navigate(Routes.Home)
|
||||||
navigate(Routes.Home)
|
|
||||||
} else {
|
|
||||||
navigate(Routes.SongRelease, { action })
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let tempSourcePath = null
|
let tempSourcePath = null
|
||||||
@@ -402,15 +399,11 @@ const PlaybackDownload = ({ route }) => {
|
|||||||
{ merge: true }
|
{ merge: true }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (action === 'playback') {
|
setTooltip({
|
||||||
setTooltip({
|
type: 'success',
|
||||||
type: 'success',
|
text: publishSuccessMessage,
|
||||||
text: 'Playback publié !',
|
})
|
||||||
})
|
navigate(Routes.Home)
|
||||||
navigate(Routes.Home)
|
|
||||||
} else {
|
|
||||||
navigate(Routes.SongRelease, { action })
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('[PlaybackDownload] publish error', {
|
console.log('[PlaybackDownload] publish error', {
|
||||||
message: error?.message,
|
message: error?.message,
|
||||||
|
|||||||
Reference in New Issue
Block a user