From 5e17f2ac887f67f1e0db92be5758321ca2edd063 Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Tue, 13 Aug 2024 08:53:47 +0200 Subject: [PATCH] fix: check for google play services before chromecast --- app/(auth)/items/[id]/page.tsx | 36 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/app/(auth)/items/[id]/page.tsx b/app/(auth)/items/[id]/page.tsx index 9a20e76a..3528431d 100644 --- a/app/(auth)/items/[id]/page.tsx +++ b/app/(auth)/items/[id]/page.tsx @@ -26,7 +26,11 @@ import { PlayButton } from "@/components/PlayButton"; import { Bitrate, BitrateSelector } from "@/components/BitrateSelector"; import { getMediaInfoApi } from "@jellyfin/sdk/lib/utils/api"; import { getStreamUrl } from "@/utils/jellyfin/media/getStreamUrl"; -import { useCastDevice, useRemoteMediaClient } from "react-native-google-cast"; +import CastContext, { + PlayServicesState, + useCastDevice, + useRemoteMediaClient, +} from "react-native-google-cast"; import { chromecastProfile } from "@/utils/profiles/chromecast"; import ios12 from "@/utils/profiles/ios12"; import { currentlyPlayingItemAtom } from "@/components/CurrentlyPlayingBar"; @@ -114,21 +118,27 @@ const page: React.FC = () => { const [cp, setCp] = useAtom(currentlyPlayingItemAtom); const client = useRemoteMediaClient(); - const onPressPlay = useCallback(() => { + const onPressPlay = useCallback(async () => { if (!playbackUrl || !item) return; if (chromecastReady && client) { - client.loadMedia({ - mediaInfo: { - contentUrl: playbackUrl, - contentType: "video/mp4", - metadata: { - type: item.Type === "Episode" ? "tvShow" : "movie", - title: item.Name || "", - subtitle: item.Overview || "", - }, - }, - startTime: 0, + await CastContext.getPlayServicesState().then((state) => { + if (state && state !== PlayServicesState.SUCCESS) + CastContext.showPlayServicesErrorDialog(state); + else { + client.loadMedia({ + mediaInfo: { + contentUrl: playbackUrl, + contentType: "video/mp4", + metadata: { + type: item.Type === "Episode" ? "tvShow" : "movie", + title: item.Name || "", + subtitle: item.Overview || "", + }, + }, + startTime: 0, + }); + } }); } else { setCp({