import { apiAtom, userAtom } from "@/providers/JellyfinProvider"; import { usePlayback } from "@/providers/PlaybackProvider"; import { getBackdropUrl } from "@/utils/jellyfin/image/getBackdropUrl"; import { getAuthHeaders } from "@/utils/jellyfin/jellyfin"; import { writeToLog } from "@/utils/log"; import { Ionicons } from "@expo/vector-icons"; import { BlurView } from "expo-blur"; import { useRouter, useSegments } from "expo-router"; import { useAtom } from "jotai"; import { useEffect, useMemo } from "react"; import { Alert, Platform, TouchableOpacity, View } from "react-native"; import Animated, { useAnimatedStyle, useSharedValue, withTiming, } from "react-native-reanimated"; import Video from "react-native-video"; import { Text } from "./common/Text"; import { Loader } from "./Loader"; import { debounce } from "lodash"; export const CurrentlyPlayingBar: React.FC = () => { const segments = useSegments(); const { currentlyPlaying, pauseVideo, playVideo, setCurrentlyPlayingState, stopPlayback, setVolume, setIsPlaying, isPlaying, videoRef, presentFullscreenPlayer, onProgress, } = usePlayback(); const [api] = useAtom(apiAtom); const [user] = useAtom(userAtom); const aBottom = useSharedValue(0); const aPadding = useSharedValue(0); const aHeight = useSharedValue(100); const router = useRouter(); const animatedOuterStyle = useAnimatedStyle(() => { return { bottom: withTiming(aBottom.value, { duration: 500 }), height: withTiming(aHeight.value, { duration: 500 }), padding: withTiming(aPadding.value, { duration: 500 }), }; }); const aPaddingBottom = useSharedValue(30); const aPaddingInner = useSharedValue(12); const aBorderRadiusBottom = useSharedValue(12); const animatedInnerStyle = useAnimatedStyle(() => { return { padding: withTiming(aPaddingInner.value, { duration: 500 }), paddingBottom: withTiming(aPaddingBottom.value, { duration: 500 }), borderBottomLeftRadius: withTiming(aBorderRadiusBottom.value, { duration: 500, }), borderBottomRightRadius: withTiming(aBorderRadiusBottom.value, { duration: 500, }), }; }); useEffect(() => { if (segments.find((s) => s.includes("tabs"))) { // Tab screen - i.e. home aBottom.value = Platform.OS === "ios" ? 78 : 50; aHeight.value = 80; aPadding.value = 8; aPaddingBottom.value = 8; aPaddingInner.value = 8; } else { // Inside a normal screen aBottom.value = Platform.OS === "ios" ? 0 : 0; aHeight.value = Platform.OS === "ios" ? 110 : 80; aPadding.value = Platform.OS === "ios" ? 0 : 8; aPaddingInner.value = Platform.OS === "ios" ? 12 : 8; aPaddingBottom.value = Platform.OS === "ios" ? 40 : 12; } }, [segments]); const startPosition = useMemo( () => currentlyPlaying?.item?.UserData?.PlaybackPositionTicks ? Math.round( currentlyPlaying?.item.UserData.PlaybackPositionTicks / 10000 ) : 0, [currentlyPlaying?.item] ); const backdropUrl = useMemo( () => getBackdropUrl({ api, item: currentlyPlaying?.item, quality: 70, width: 200, }), [currentlyPlaying?.item, api] ); if (!api || !currentlyPlaying) return null; return ( { videoRef.current?.presentFullscreenPlayer(); }} className={`relative h-full bg-neutral-800 rounded-md overflow-hidden ${ currentlyPlaying.item?.Type === "Audio" ? "aspect-square" : "aspect-video" } `} > {currentlyPlaying?.url && ( { if (currentlyPlaying.item?.Type === "Audio") router.push(`/albums/${currentlyPlaying.item?.AlbumId}`); else router.push(`/items/${currentlyPlaying.item?.Id}`); }} > {currentlyPlaying.item?.Name} {currentlyPlaying.item?.Type === "Episode" && ( { router.push( `/(auth)/series/${currentlyPlaying.item.SeriesId}` ); }} className="text-xs opacity-50" > {currentlyPlaying.item.SeriesName} )} {currentlyPlaying.item?.Type === "Movie" && ( {currentlyPlaying.item?.ProductionYear} )} {currentlyPlaying.item?.Type === "Audio" && ( { router.push(`/albums/${currentlyPlaying.item?.AlbumId}`); }} > {currentlyPlaying.item?.Album} )} { if (isPlaying) pauseVideo(); else playVideo(); }} className="aspect-square rounded flex flex-col items-center justify-center p-2" > {isPlaying ? ( ) : ( )} { stopPlayback(); }} className="aspect-square rounded flex flex-col items-center justify-center p-2" > ); };