From 9e2740c84eb3dbb2f288aa018251dc98f1a68ae2 Mon Sep 17 00:00:00 2001 From: austinried <4966622+austinried@users.noreply.github.com> Date: Tue, 29 Jun 2021 15:48:21 +0900 Subject: [PATCH] streaming tracks! also managing the queue for playing from album view --- src/components/common/AlbumView.tsx | 148 +++++++++++++++++-------- src/components/common/BottomTabBar.tsx | 103 ++++++++++------- src/hooks/player.ts | 75 +++++++++++++ src/hooks/subsonic.ts | 14 +++ src/models/music.ts | 3 + src/playback/service.ts | 4 +- src/state/music.ts | 10 +- src/styles/colors.ts | 4 +- src/subsonic/api.ts | 6 +- src/subsonic/params.ts | 7 ++ 10 files changed, 278 insertions(+), 96 deletions(-) create mode 100644 src/hooks/player.ts create mode 100644 src/hooks/subsonic.ts diff --git a/src/components/common/AlbumView.tsx b/src/components/common/AlbumView.tsx index 3191732..8fd1311 100644 --- a/src/components/common/AlbumView.tsx +++ b/src/components/common/AlbumView.tsx @@ -1,7 +1,9 @@ import { useNavigation } from '@react-navigation/native'; import { useAtomValue } from 'jotai/utils'; -import React, { useEffect } from 'react'; -import { ScrollView, Text, useWindowDimensions, View, Image, Pressable, GestureResponderEvent } from 'react-native'; +import React, { useEffect, useState } from 'react'; +import { GestureResponderEvent, Image, Pressable, ScrollView, Text, useWindowDimensions, View } from 'react-native'; +import { TrackPlayerEvents } from 'react-native-track-player'; +import { useCurrentTrackId, useSetQueue } from '../../hooks/player'; import { albumAtomFamily } from '../../state/music'; import colors from '../../styles/colors'; import text from '../../styles/text'; @@ -24,15 +26,21 @@ const Button: React.FC<{ title: string; onPress: (event: GestureResponderEvent) => void; }> = ({ title, onPress }) => { + const [opacity, setOpacity] = useState(1); + return ( setOpacity(0.6)} + onPressOut={() => setOpacity(1)} + onLongPress={() => setOpacity(1)} style={{ backgroundColor: colors.accent, paddingHorizontal: 24, minHeight: 42, justifyContent: 'center', borderRadius: 1000, + opacity, }} > {title} @@ -40,13 +48,90 @@ const Button: React.FC<{ ); } +const songEvents = [ + TrackPlayerEvents.PLAYBACK_STATE, + TrackPlayerEvents.PLAYBACK_TRACK_CHANGED, +] + +const SongItem: React.FC<{ + id: string; + title: string + artist?: string; + onPress: (event: GestureResponderEvent) => void; +}> = ({ id, title, artist, onPress }) => { + const [opacity, setOpacity] = useState(1); + const currentTrackId = useCurrentTrackId(); + + return ( + + setOpacity(0.6)} + onPressOut={() => setOpacity(1)} + onLongPress={() => setOpacity(1)} + style={{ + flex: 1, + opacity, + }} + > + {title} + {artist} + + + {/* {secondsToTime(duration || 0)} */} + + + + + ); +} + const AlbumDetails: React.FC<{ id: string, }> = ({ id }) => { const album = useAtomValue(albumAtomFamily(id)); const layout = useWindowDimensions(); + const setQueue = useSetQueue(); - const coverSize = layout.width - layout.width / 2; + const coverSize = layout.width - layout.width / 2.5; + + if (!album) { + return ( + No Album + ); + } return ( {album?.name} + }}>{album.name} {album?.artist}{album?.year ? ` • ${album.year}` : ''} + }}>{album.artist}{album.year ? ` • ${album.year}` : ''}