diff --git a/app/(auth)/player/direct-player.tsx b/app/(auth)/player/direct-player.tsx index 370150a7..b0997e88 100644 --- a/app/(auth)/player/direct-player.tsx +++ b/app/(auth)/player/direct-player.tsx @@ -342,22 +342,11 @@ export default function page() { : 0; }, [item]); - const backAction = () => { - videoRef.current?.stop(); - return false; - }; - useFocusEffect( React.useCallback(() => { - const onBackPress = () => { - return backAction(); - }; - - BackHandler.addEventListener("hardwareBackPress", onBackPress); - return async () => { - videoRef.current?.stop(); - BackHandler.removeEventListener("hardwareBackPress", onBackPress); + stop(); + console.log("Unmounted"); }; }, []) ); diff --git a/app/(auth)/player/transcoding-player.tsx b/app/(auth)/player/transcoding-player.tsx index f9441a13..e2d23431 100644 --- a/app/(auth)/player/transcoding-player.tsx +++ b/app/(auth)/player/transcoding-player.tsx @@ -362,23 +362,10 @@ const Player = () => { })); }; - const backAction = () => { - videoRef.current?.pause(); - return false; - }; - useFocusEffect( React.useCallback(() => { - const onBackPress = () => { - return backAction(); - }; - - BackHandler.addEventListener("hardwareBackPress", onBackPress); - play(); - return async () => { - videoRef.current?.pause(); - BackHandler.removeEventListener("hardwareBackPress", onBackPress); + stop(); }; }, []) ); diff --git a/components/video-player/controls/Controls.tsx b/components/video-player/controls/Controls.tsx index f7b7940d..6460557a 100644 --- a/components/video-player/controls/Controls.tsx +++ b/components/video-player/controls/Controls.tsx @@ -526,7 +526,6 @@ export const Controls: React.FC = ({ )} { - if (stop) await stop(); router.back(); }} className="aspect-square flex flex-col bg-neutral-800/90 rounded-xl items-center justify-center p-2" diff --git a/components/video-player/controls/EpisodeList.tsx b/components/video-player/controls/EpisodeList.tsx index f3ddfbc9..bdd42ee9 100644 --- a/components/video-player/controls/EpisodeList.tsx +++ b/components/video-player/controls/EpisodeList.tsx @@ -17,7 +17,7 @@ import { HorizontalScroll, HorizontalScrollRef, } from "@/components/common/HorrizontalScroll"; -import { router } from "expo-router"; +import { router, useLocalSearchParams } from "expo-router"; import { getDefaultPlaySettings } from "@/utils/jellyfin/getDefaultPlaySettings"; import { getItemById } from "@/utils/jellyfin/user-library/getItemById"; import { useSettings } from "@/utils/atoms/settings"; @@ -155,22 +155,28 @@ export const EpisodeList: React.FC = ({ item, close }) => { } }, [episodes, item.Id]); + const { audioIndex, subtitleIndex, bitrateValue } = useLocalSearchParams<{ + audioIndex: string; + subtitleIndex: string; + mediaSourceId: string; + bitrateValue: string; + }>(); + const gotoEpisode = async (itemId: string) => { const item = await getItemById(api, itemId); if (!settings || !item) return; - const { bitrate, mediaSource, audioIndex, subtitleIndex } = - getDefaultPlaySettings(item, settings); + const { mediaSource } = getDefaultPlaySettings(item, settings); const queryParams = new URLSearchParams({ itemId: item.Id ?? "", // Ensure itemId is a string audioIndex: audioIndex?.toString() ?? "", subtitleIndex: subtitleIndex?.toString() ?? "", mediaSourceId: mediaSource?.Id ?? "", // Ensure mediaSourceId is a string - bitrateValue: bitrate.toString(), + bitrateValue: bitrateValue, }).toString(); - if (!bitrate.value) { + if (!bitrateValue) { // @ts-expect-error router.replace(`player/direct-player?${queryParams}`); return; @@ -179,116 +185,105 @@ export const EpisodeList: React.FC = ({ item, close }) => { router.replace(`player/transcoding-player?${queryParams}`); }; + if (!episodes) { + return ; + } + return ( - {isFetching ? ( - - - - ) : ( - <> - - {seriesItem && ( - { - setSeasonIndexState((prev) => ({ - ...prev, - [item.SeriesId ?? ""]: season.IndexNumber, - })); - }} - /> - )} - { - close(); - }} - className="aspect-square flex flex-col bg-neutral-800/90 rounded-xl items-center justify-center p-2" - > - - - - - ( - - { - gotoEpisode(_item.Id); - }} - > - - - - - {_item.Name} - - - {`S${_item.ParentIndexNumber?.toString()}:E${_item.IndexNumber?.toString()}`} - - - {runtimeTicksToSeconds(_item.RunTimeTicks)} - - - - - - - {_item.Overview} - - - )} - keyExtractor={(e: BaseItemDto) => e.Id ?? ""} - estimatedItemSize={200} - showsHorizontalScrollIndicator={false} - contentContainerStyle={{ - paddingHorizontal: 16, + <> + + {seriesItem && ( + { + setSeasonIndexState((prev) => ({ + ...prev, + [item.SeriesId ?? ""]: season.IndexNumber, + })); }} /> - - - )} + )} + { + close(); + }} + className="aspect-square flex flex-col bg-neutral-800/90 rounded-xl items-center justify-center p-2" + > + + + + + ( + + { + gotoEpisode(_item.Id); + }} + > + + + + + {_item.Name} + + + {`S${_item.ParentIndexNumber?.toString()}:E${_item.IndexNumber?.toString()}`} + + + {runtimeTicksToSeconds(_item.RunTimeTicks)} + + + + + + + {_item.Overview} + + + )} + keyExtractor={(e: BaseItemDto) => e.Id ?? ""} + estimatedItemSize={200} + showsHorizontalScrollIndicator={false} + /> + ); };