From caac40c4b123e83ce15062d99261620f7dea54d7 Mon Sep 17 00:00:00 2001 From: Fredrik Burmester Date: Fri, 13 Sep 2024 13:07:47 +0300 Subject: [PATCH] wip --- components/CurrentlyPlayingBar.tsx | 218 ++++++++++++++++++++--------- 1 file changed, 152 insertions(+), 66 deletions(-) diff --git a/components/CurrentlyPlayingBar.tsx b/components/CurrentlyPlayingBar.tsx index 3bc7f01c..75f00ef5 100644 --- a/components/CurrentlyPlayingBar.tsx +++ b/components/CurrentlyPlayingBar.tsx @@ -20,6 +20,8 @@ import { Text } from "./common/Text"; import { Loader } from "./Loader"; import { Dimensions } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; +import { Bubble, Slider } from "react-native-awesome-slider"; +import { runtimeTicksToMinutes } from "@/utils/time"; export const CurrentlyPlayingBar: React.FC = () => { const segments = useSegments(); @@ -66,6 +68,22 @@ export const CurrentlyPlayingBar: React.FC = () => { right: 16, }); + const textValues = useSharedValue({ + height: 70, + bottom: 90, + left: 149, + width: 140, + }); + + const animatedTextStyle = useAnimatedStyle(() => { + return { + bottom: withTiming(textValues.value.bottom, { duration: 500 }), + left: withTiming(textValues.value.left, { duration: 500 }), + height: withTiming(textValues.value.height, { duration: 500 }), + width: withTiming(textValues.value.width, { duration: 500 }), + }; + }); + const animatedButtonStyle = useAnimatedStyle(() => { return { bottom: withTiming(buttonsValues.value.bottom, { duration: 500 }), @@ -84,6 +102,18 @@ export const CurrentlyPlayingBar: React.FC = () => { }; }); + const poster = useMemo(() => { + if (currentlyPlaying?.item.Type === "Audio") + return `${api?.basePath}/Items/${currentlyPlaying.item.AlbumId}/Images/Primary?tag=${currentlyPlaying.item.AlbumPrimaryImageTag}&quality=90&maxHeight=200&maxWidth=200`; + else + return getBackdropUrl({ + api, + item: currentlyPlaying?.item, + quality: 70, + width: 200, + }); + }, [currentlyPlaying?.item.Id, api]); + const startPosition = useMemo( () => currentlyPlaying?.item?.UserData?.PlaybackPositionTicks @@ -126,12 +156,6 @@ export const CurrentlyPlayingBar: React.FC = () => { }; }); - const animatedValues = useSharedValue({ - paddingBottom: 0, - paddingInner: 0, - borderRadiusBottom: 0, - }); - useEffect(() => { if (size === "full") { backgroundValues.value = { @@ -171,18 +195,39 @@ export const CurrentlyPlayingBar: React.FC = () => { width: 113, left: 16, }; + textValues.value = { + bottom: 78, + height: 64, + left: 141, + width: 140, + }; } }, [size, screenHeight, insets]); + const progress = useSharedValue(0); + const min = useSharedValue(0); + const max = useSharedValue(currentlyPlaying?.item.RunTimeTicks || 0); + + useEffect(() => { + max.value = currentlyPlaying?.item.RunTimeTicks || 0; + }, [currentlyPlaying?.item.RunTimeTicks]); + if (!api || !currentlyPlaying) return null; return ( <> + + {currentlyPlaying.item.Name} + + { - - {videoSource && ( - + }} + onVolumeChange={(e) => { + setVolume(e.volume); + }} + progressUpdateInterval={4000} + onError={(e) => { + console.log(e); + writeToLog("ERROR", "Video playback error: " + JSON.stringify(e)); + Alert.alert("Error", "Cannot play this video file."); + setIsPlaying(false); + // setCurrentlyPlaying(null); + }} + renderLoader={ + currentlyPlaying.item?.Type !== "Audio" && ( + + + + ) + } + /> + )} + {size === "full" && ( + + { + const tick = Math.floor(val); + console.log(tick); + videoRef.current?.seek(tick); + progress.value = tick; + }} + containerStyle={{ + borderRadius: 100, + }} + bubble={(s) => runtimeTicksToMinutes(s)} + sliderHeight={12} + thumbWidth={0} + progress={progress} + minimumValue={min} + maximumValue={max} + /> + + {runtimeTicksToMinutes(progress.value)} + + + )} {/*