mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 12:13:25 +00:00
feat: audio track switching
This commit is contained in:
@@ -55,6 +55,7 @@ export const VideoPlayer = () => {
|
||||
const isIdle = usePlayerStore((state) => state.interface.isIdle);
|
||||
const stream = usePlayerStore((state) => state.interface.currentStream);
|
||||
const selectedAudioTrack = useAudioTrackStore((state) => state.selectedTrack);
|
||||
const videoRef = usePlayerStore((state) => state.videoRef);
|
||||
const setVideoRef = usePlayerStore((state) => state.setVideoRef);
|
||||
const setStatus = usePlayerStore((state) => state.setStatus);
|
||||
const setIsIdle = usePlayerStore((state) => state.setIsIdle);
|
||||
@@ -227,6 +228,26 @@ export const VideoPlayer = () => {
|
||||
setHasStartedPlaying(true);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const synchronizePlayback = async () => {
|
||||
if (videoRef && hasStartedPlaying) {
|
||||
const videoStatus = await videoRef.getStatusAsync();
|
||||
|
||||
if (selectedAudioTrack && audioObject && videoStatus.isLoaded) {
|
||||
await videoRef.setIsMutedAsync(true);
|
||||
await audioObject.setPositionAsync(videoStatus.positionMillis);
|
||||
await audioObject.playAsync();
|
||||
} else {
|
||||
await videoRef.setIsMutedAsync(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (hasStartedPlaying) {
|
||||
void synchronizePlayback();
|
||||
}
|
||||
}, [audioObject, hasStartedPlaying, selectedAudioTrack, videoRef]);
|
||||
|
||||
return (
|
||||
<GestureDetector gesture={composedGesture}>
|
||||
<View className="flex-1 items-center justify-center bg-black">
|
||||
|
Reference in New Issue
Block a user