From 1c2578477a11409ce6b0c441ecc18377d9b6ef5b Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Sun, 29 Sep 2024 14:48:51 +0200 Subject: [PATCH] fix: app not reporting playback started on first start --- components/FullScreenVideoPlayer.tsx | 11 ++++------- providers/PlaybackProvider.tsx | 4 ++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/FullScreenVideoPlayer.tsx b/components/FullScreenVideoPlayer.tsx index 54a1db7f..ef762299 100644 --- a/components/FullScreenVideoPlayer.tsx +++ b/components/FullScreenVideoPlayer.tsx @@ -66,6 +66,9 @@ export const FullScreenVideoPlayer: React.FC = () => { const [showControls, setShowControls] = useState(true); const [isBuffering, setIsBufferingState] = useState(true); const [ignoreSafeArea, setIgnoreSafeArea] = useState(false); + const [orientation, setOrientation] = useState( + ScreenOrientation.OrientationLock.UNKNOWN + ); // Seconds const [currentTime, setCurrentTime] = useState(0); @@ -162,13 +165,6 @@ export const FullScreenVideoPlayer: React.FC = () => { return () => backHandler.remove(); }, [currentlyPlaying, stopPlayback, router]); - const [orientation, setOrientation] = useState( - ScreenOrientation.OrientationLock.UNKNOWN - ); - - /** - * Event listener for orientation - */ useEffect(() => { const subscription = ScreenOrientation.addOrientationChangeListener( (event) => { @@ -232,6 +228,7 @@ export const FullScreenVideoPlayer: React.FC = () => { currentlyPlaying.item?.UserData?.PlaybackPositionTicks || 0; max.value = currentlyPlaying.item.RunTimeTicks || 0; setShowControls(true); + playVideo(); } }, [currentlyPlaying]); diff --git a/providers/PlaybackProvider.tsx b/providers/PlaybackProvider.tsx index 22c54631..22013463 100644 --- a/providers/PlaybackProvider.tsx +++ b/providers/PlaybackProvider.tsx @@ -29,6 +29,7 @@ import { parseM3U8ForSubtitles, SubtitleTrack, } from "@/utils/hls/parseM3U8ForSubtitles"; +import { useRouter } from "expo-router"; export type CurrentlyPlayingState = { url: string; @@ -70,6 +71,8 @@ export const PlaybackProvider: React.FC<{ children: ReactNode }> = ({ const [api] = useAtom(apiAtom); const [user] = useAtom(userAtom); + const router = useRouter(); + const videoRef = useRef(null); const [settings] = useSettings(); @@ -326,6 +329,7 @@ export const PlaybackProvider: React.FC<{ children: ReactNode }> = ({ } else if (command === "Stop") { console.log("Command ~ Stop"); stopPlayback(); + router.canGoBack() && router.back(); } else if (command === "Mute") { console.log("Command ~ Mute"); setVolume(0);