feat: poster

This commit is contained in:
Fredrik Burmester
2024-08-13 13:26:31 +02:00
parent 11f9d0fe33
commit b05b43c12e

View File

@@ -28,6 +28,9 @@ import Animated, {
} from "react-native-reanimated"; } from "react-native-reanimated";
import { useRouter, useSegments } from "expo-router"; import { useRouter, useSegments } from "expo-router";
import { BlurView } from "expo-blur"; import { BlurView } from "expo-blur";
import { writeToLog } from "@/utils/log";
import { getBackdropUrl } from "@/utils/jellyfin/image/getBackdropUrl";
import { Image } from "expo-image";
export const currentlyPlayingItemAtom = atom<{ export const currentlyPlayingItemAtom = atom<{
item: BaseItemDto; item: BaseItemDto;
@@ -173,6 +176,17 @@ export const CurrentlyPlayingBar: React.FC = () => {
[item], [item],
); );
const backdropUrl = useMemo(
() =>
getBackdropUrl({
api,
item,
quality: 70,
width: 200,
}),
[item],
);
useEffect(() => { useEffect(() => {
if (cp?.playbackUrl) { if (cp?.playbackUrl) {
play(); play();
@@ -203,31 +217,50 @@ export const CurrentlyPlayingBar: React.FC = () => {
onPress={() => { onPress={() => {
videoRef.current?.presentFullscreenPlayer(); videoRef.current?.presentFullscreenPlayer();
}} }}
className="aspect-video h-full bg-neutral-800 rounded-md overflow-hidden" className={`relative h-full bg-neutral-800 rounded-md overflow-hidden
${item?.Type === "Audio" ? "aspect-square" : "aspect-video"}
`}
> >
{cp.playbackUrl && ( {cp.playbackUrl && (
<Video <Video
ref={videoRef}
style={{ width: "100%", height: "100%" }} style={{ width: "100%", height: "100%" }}
allowsExternalPlayback={true}
playInBackground={true}
playWhenInactive={true}
showNotificationControls={true}
ignoreSilentSwitch="ignore"
controls={false}
poster={backdropUrl ? backdropUrl : undefined}
paused={paused}
onProgress={(e) => onProgress(e)}
subtitleStyle={{
fontSize: 16,
}}
source={{ source={{
uri: cp.playbackUrl, uri: cp.playbackUrl,
isNetwork: true, isNetwork: true,
startPosition, startPosition,
}} }}
controls={false}
ref={videoRef}
onBuffer={(e) => onBuffer={(e) =>
e.isBuffering ? console.log("Buffering...") : null e.isBuffering ? console.log("Buffering...") : null
} }
onProgress={(e) => onProgress(e)}
paused={paused}
onFullscreenPlayerDidDismiss={() => { onFullscreenPlayerDidDismiss={() => {
play(); play();
}} }}
ignoreSilentSwitch="ignore" onError={(e) => {
console.log(e);
writeToLog(
"ERROR",
"Video playback error: " + JSON.stringify(e),
);
}}
renderLoader={ renderLoader={
<View className="flex flex-col items-center justify-center h-full"> item?.Type === "Video" && (
<ActivityIndicator size={"small"} color={"white"} /> <View className="flex flex-col items-center justify-center h-full">
</View> <ActivityIndicator size={"small"} color={"white"} />
</View>
)
} }
/> />
)} )}