mirror of
https://github.com/Jellify-Music/App.git
synced 2026-05-01 07:59:55 -05:00
what about this for the flciker fix?
This commit is contained in:
@@ -22,10 +22,8 @@ const playerEvents = [
|
||||
|
||||
export default function Player(): React.JSX.Element {
|
||||
|
||||
const activeTrack = useActiveTrack() as JellifyTrack | undefined;
|
||||
|
||||
const { apiClient } = useApiClientContext();
|
||||
const { queue, setPlayerState } = usePlayerContext();
|
||||
const { queue, setPlayerState, nowPlaying } = usePlayerContext();
|
||||
|
||||
useTrackPlayerEvents(playerEvents, (event : any) => {
|
||||
playerEventCallback(event, setPlayerState)
|
||||
@@ -33,13 +31,13 @@ export default function Player(): React.JSX.Element {
|
||||
|
||||
return (
|
||||
<SafeAreaView>
|
||||
{ activeTrack && (
|
||||
{ nowPlaying && (
|
||||
<YStack alignItems="center">
|
||||
|
||||
<CachedImage
|
||||
source={getImageApi(apiClient!)
|
||||
.getItemImageUrlById(
|
||||
activeTrack!.AlbumId,
|
||||
nowPlaying!.AlbumId,
|
||||
ImageType.Primary,
|
||||
{ ...queryConfig.playerArtwork }
|
||||
)
|
||||
@@ -53,8 +51,8 @@ export default function Player(): React.JSX.Element {
|
||||
<Stack justifyContent="space-between">
|
||||
|
||||
<Stack alignItems="flex-start" justifyContent="flex-start">
|
||||
<Text>{activeTrack?.title ?? "Untitled Track"}</Text>
|
||||
<Text bold>{activeTrack?.artist ?? "Unknown Artist"}</Text>
|
||||
<Text>{nowPlaying?.title ?? "Untitled Track"}</Text>
|
||||
<Text bold>{nowPlaying?.artist ?? "Unknown Artist"}</Text>
|
||||
</Stack>
|
||||
|
||||
</Stack>
|
||||
|
||||
@@ -19,33 +19,16 @@ export function Miniplayer({ navigation }: { navigation : NavigationHelpers<Para
|
||||
|
||||
const playbackState = usePlaybackState();
|
||||
|
||||
const activeTrack = useActiveTrack() as JellifyTrack | undefined;
|
||||
|
||||
const [nowPlaying, setNowPlaying] = useState<JellifyTrack | undefined>();
|
||||
|
||||
const { play, pause } = usePlayerContext();
|
||||
const { nowPlaying, play, pause } = usePlayerContext();
|
||||
|
||||
const { apiClient } = useApiClientContext();
|
||||
|
||||
useMemo(() => {
|
||||
|
||||
/**
|
||||
* When we are skipping to an index in the queue
|
||||
* (like when a track in the middle of an album is queued),
|
||||
* prevent flickering of the first queue item.
|
||||
*/
|
||||
setTimeout(() => {
|
||||
setNowPlaying(activeTrack);
|
||||
}, 500)
|
||||
}, [
|
||||
activeTrack
|
||||
])
|
||||
|
||||
return (
|
||||
<BlurView>
|
||||
{ nowPlaying && (
|
||||
|
||||
<XStack
|
||||
alignContent="center"
|
||||
height={"$6"}
|
||||
onPress={() => navigation.navigate("Player")}
|
||||
>
|
||||
@@ -67,14 +50,14 @@ export function Miniplayer({ navigation }: { navigation : NavigationHelpers<Para
|
||||
}}
|
||||
/>
|
||||
|
||||
<YStack justifyContent="flex-start" flex={3}>
|
||||
<YStack alignContent="flex-start">
|
||||
<Text bold>{nowPlaying?.title ?? "Nothing Playing"}</Text>
|
||||
<Text>{nowPlaying?.artist ?? ""}</Text>
|
||||
</YStack>
|
||||
|
||||
<Spacer />
|
||||
|
||||
<XStack alignItems="flex-end" flex={1}>
|
||||
<XStack alignItems="flex-end">
|
||||
{ playbackState.state === State.Playing && (
|
||||
<Icon name="pause" large onPress={() => pause()} />
|
||||
)}
|
||||
|
||||
+17
-1
@@ -14,6 +14,7 @@ interface PlayerContext {
|
||||
setShowPlayer: React.Dispatch<SetStateAction<boolean>>;
|
||||
showMiniplayer: boolean;
|
||||
setShowMiniplayer: React.Dispatch<SetStateAction<boolean>>;
|
||||
nowPlaying: JellifyTrack | undefined;
|
||||
queue: JellifyTrack[];
|
||||
play: (index?: number | undefined) => Promise<void>,
|
||||
pause: () => Promise<void>,
|
||||
@@ -32,6 +33,8 @@ const PlayerContextInitializer = () => {
|
||||
//#region State
|
||||
const [showPlayer, setShowPlayer] = useState<boolean>(false);
|
||||
const [showMiniplayer, setShowMiniplayer] = useState<boolean>(false);
|
||||
|
||||
const [nowPlaying, setNowPlaying] = useState<JellifyTrack | undefined>(undefined);
|
||||
const [queue, setQueue] = useState<JellifyTrack[]>(queueJson ? JSON.parse(queueJson) : []);
|
||||
//#endregion State
|
||||
|
||||
@@ -45,6 +48,8 @@ const PlayerContextInitializer = () => {
|
||||
TrackPlayer.play();
|
||||
|
||||
const activeTrack = await TrackPlayer.getActiveTrack() as JellifyTrack;
|
||||
|
||||
setNowPlaying(activeTrack);
|
||||
playStateApi.reportPlaybackStart({
|
||||
playbackStartInfo: {
|
||||
SessionId: sessionId,
|
||||
@@ -65,7 +70,7 @@ const PlayerContextInitializer = () => {
|
||||
})
|
||||
}
|
||||
|
||||
const resetQueue = async (hideMiniplayer: boolean | undefined) => {
|
||||
const resetQueue = async (hideMiniplayer?: boolean | undefined) => {
|
||||
console.debug("Clearing queue")
|
||||
await TrackPlayer.reset();
|
||||
setQueue([]);
|
||||
@@ -113,6 +118,13 @@ const PlayerContextInitializer = () => {
|
||||
}, [
|
||||
playbackState
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
if (!showMiniplayer)
|
||||
setNowPlaying(undefined);
|
||||
}, [
|
||||
showMiniplayer
|
||||
])
|
||||
//#endregion RNTP Setup
|
||||
|
||||
return {
|
||||
@@ -120,6 +132,7 @@ const PlayerContextInitializer = () => {
|
||||
setShowPlayer,
|
||||
showMiniplayer,
|
||||
setShowMiniplayer,
|
||||
nowPlaying,
|
||||
queue,
|
||||
play,
|
||||
pause,
|
||||
@@ -134,6 +147,7 @@ export const PlayerContext = createContext<PlayerContext>({
|
||||
setShowPlayer: () => {},
|
||||
showMiniplayer: false,
|
||||
setShowMiniplayer: () => {},
|
||||
nowPlaying: undefined,
|
||||
queue: [],
|
||||
play: async (index?: number | undefined) => {},
|
||||
pause: async () => {},
|
||||
@@ -148,6 +162,7 @@ export const PlayerProvider: ({ children }: { children: ReactNode }) => React.JS
|
||||
setShowPlayer,
|
||||
showMiniplayer,
|
||||
setShowMiniplayer,
|
||||
nowPlaying,
|
||||
queue,
|
||||
play,
|
||||
pause,
|
||||
@@ -161,6 +176,7 @@ export const PlayerProvider: ({ children }: { children: ReactNode }) => React.JS
|
||||
setShowPlayer,
|
||||
showMiniplayer,
|
||||
setShowMiniplayer,
|
||||
nowPlaying,
|
||||
queue,
|
||||
play,
|
||||
pause,
|
||||
|
||||
Reference in New Issue
Block a user