From cb4c4f193e45edc19c03de11bbad103784638921 Mon Sep 17 00:00:00 2001 From: Violet Caulfield Date: Mon, 13 Jan 2025 06:30:16 -0600 Subject: [PATCH] Add time codes to player Adjust track component --- components/Album/component.tsx | 2 +- components/Global/components/track.tsx | 10 +++---- .../{runtimeticks.tsx => time-codes.tsx} | 26 ++++++++++++------- components/Player/component.tsx | 17 +++++++++--- components/Playlist/component.tsx | 4 +-- 5 files changed, 39 insertions(+), 20 deletions(-) rename components/Global/helpers/{runtimeticks.tsx => time-codes.tsx} (56%) diff --git a/components/Album/component.tsx b/components/Album/component.tsx index c74ee4ed..f6f9f1a4 100644 --- a/components/Album/component.tsx +++ b/components/Album/component.tsx @@ -9,7 +9,7 @@ import { queryConfig } from "../../api/queries/query.config"; import { H4, H5, Text } from "../Global/helpers/text"; import { FlatList } from "react-native"; import { usePlayerContext } from "../../player/provider"; -import RunTimeTicks from "../Global/helpers/runtimeticks"; +import { RunTimeTicks } from "../Global/helpers/time-codes"; import Track from "../Global/components/track"; import { useItemTracks } from "@/api/queries/tracks"; import { SafeAreaView, useSafeAreaFrame } from "react-native-safe-area-context"; diff --git a/components/Global/components/track.tsx b/components/Global/components/track.tsx index eb07f5bd..ae7e3e80 100644 --- a/components/Global/components/track.tsx +++ b/components/Global/components/track.tsx @@ -1,8 +1,8 @@ import { usePlayerContext } from "@/player/provider"; import React from "react"; -import { Separator, useTheme, View, XStack } from "tamagui"; +import { Separator, useTheme, View, XStack, YStack } from "tamagui"; import { Text } from "../helpers/text"; -import RunTimeTicks from "../helpers/runtimeticks"; +import RunTimeTicks from "../helpers/time-codes"; import { useApiClientContext } from "../../jellyfin-api-provider"; import { mapDtoToTrack } from "@/helpers/mappings"; import { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; @@ -44,7 +44,7 @@ export default function Track({ }); }} paddingVertical={"$3"} - paddingHorizontal={"$1"} + marginHorizontal={"$1"} > @@ -52,7 +52,7 @@ export default function Track({ - + { track.Name ?? "Untitled Track" } - + { track.RunTimeTicks } diff --git a/components/Global/helpers/runtimeticks.tsx b/components/Global/helpers/time-codes.tsx similarity index 56% rename from components/Global/helpers/runtimeticks.tsx rename to components/Global/helpers/time-codes.tsx index f03a10a7..9597aea2 100644 --- a/components/Global/helpers/runtimeticks.tsx +++ b/components/Global/helpers/time-codes.tsx @@ -1,8 +1,12 @@ -import { pad } from "lodash"; import { Text } from "./text"; import { convertRunTimeTicksToSeconds } from "@/helpers/runtimeticks"; +import React from "react"; -export default function RunTimeTicks({ children } : { children?: number | null | undefined }) : React.JSX.Element { +export function RunTimeSeconds({ children }: { children: number }) : React.JSX.Element { + return { calculateRunTimeFromSeconds(children) } +} + +export function RunTimeTicks({ children } : { children?: number | null | undefined }) : React.JSX.Element { if (!!!children) return 0:00 @@ -11,18 +15,22 @@ export default function RunTimeTicks({ children } : { children?: number | null | return { time } } +function calculateRunTimeFromSeconds(seconds: number) : string { + const runTimeHours = Math.floor(seconds / 3600); + const runTimeMinutes = Math.floor((seconds % 3600) / 60) + const runTimeSeconds = seconds % 60; + + return (runTimeHours != 0 ? `${padRunTimeNumber(runTimeHours)}:` : "") + + (runTimeHours != 0 ? `${padRunTimeNumber(runTimeMinutes)}:` : `${runTimeMinutes}:`) + + (padRunTimeNumber(runTimeSeconds)); +} + function calculateRunTimeFromTicks(runTimeTicks: number) : string { const runTimeTotalSeconds = convertRunTimeTicksToSeconds(runTimeTicks); - const runTimeHours = Math.floor(runTimeTotalSeconds / 3600); - const runTimeMinutes = Math.floor((runTimeTotalSeconds % 3600) / 60) - const runTimeSeconds = runTimeTotalSeconds % 60; - - return (runTimeHours != 0 ? `${padRunTimeNumber(runTimeHours)}:` : "") + - (runTimeHours != 0 ? `${padRunTimeNumber(runTimeMinutes)}:` : `${runTimeMinutes}:`) + - (padRunTimeNumber(runTimeSeconds)); + return calculateRunTimeFromSeconds(runTimeTotalSeconds); } function padRunTimeNumber(number: number) : string { diff --git a/components/Player/component.tsx b/components/Player/component.tsx index 0c6c6cd5..743da3a5 100644 --- a/components/Player/component.tsx +++ b/components/Player/component.tsx @@ -5,7 +5,7 @@ import { useApiClientContext } from "../jellyfin-api-provider"; import { getImageApi } from "@jellyfin/sdk/lib/utils/api"; import { ImageType } from "@jellyfin/sdk/lib/generated-client/models"; import { queryConfig } from "../../api/queries/query.config"; -import { Text } from "../Global/helpers/text"; +import { H5, Text } from "../Global/helpers/text"; import { useSafeAreaFrame } from "react-native-safe-area-context"; import { HorizontalSlider } from "../Global/helpers/slider"; import PlayPauseButton from "./helpers/buttons"; @@ -14,6 +14,7 @@ import { skipToNext, skipToPrevious } from "react-native-track-player/lib/src/tr import Icon from "../Global/helpers/icon"; import { NativeStackNavigationProp } from "@react-navigation/native-stack"; import { StackParamList } from "../types"; +import { RunTimeSeconds } from "../Global/helpers/time-codes"; export default function Player({ navigation }: { navigation: NativeStackNavigationProp}): React.JSX.Element { @@ -47,6 +48,11 @@ export default function Player({ navigation }: { navigation: NativeStackNavigati <> + + Playing from +
THING
+
+ - + {/* playback progress goes here */} { @@ -118,6 +124,11 @@ export default function Player({ navigation }: { navigation: NativeStackNavigati + + {progress!.position} + {progress!.duration} + + +