import React, { useState, useCallback } from 'react'; import TrackPlayer, { Event, State, usePlaybackState, useTrackPlayerEvents } from 'react-native-track-player'; import { TouchableOpacity, useColorScheme } from 'react-native'; import styled from 'styled-components/native'; import { useHasNextQueue, useHasPreviousQueue } from 'utility/useQueue'; import ForwardIcon from 'assets/forwards.svg'; import BackwardIcon from 'assets/backwards.svg'; import PlayIcon from 'assets/play.svg'; import PauseIcon from 'assets/pause.svg'; import RepeatIcon from 'assets/repeat.svg'; // import ShuffleIcon from 'assets/shuffle.svg'; import { THEME_COLOR } from 'CONSTANTS'; import Casting from './Casting'; const BUTTON_SIZE = 40; const BUTTON_SIZE_SMALL = 25; const pause = TrackPlayer.pause; const play = TrackPlayer.play; const next = TrackPlayer.skipToNext; const previous = TrackPlayer.skipToPrevious; const Container = styled.View` align-items: center; margin: 20px 0; `; const Buttons = styled.View` flex-direction: row; align-items: center; justify-content: space-between; width: 100%; `; const Button = styled.View` margin: 20px 40px; `; export default function MediaControls() { const scheme = useColorScheme(); const fill = scheme === 'dark' ? '#ffffff' : '#000000'; return ( ); } export function PreviousButton({ fill }: { fill: string }) { const hasQueue = useHasPreviousQueue(); return ( ); } export function NextButton({ fill }: { fill: string }) { const hasQueue = useHasNextQueue(); return ( ); } export function RepeatButton({ fill }: { fill: string}) { const [isRepeating, setRepeating] = useState(false); const handlePress = useCallback(() => setRepeating(!isRepeating), [isRepeating, setRepeating]); // The callback that should determine whether we need to repeeat or not useTrackPlayerEvents([Event.PlaybackQueueEnded], async () => { if (isRepeating) { // Skip to the first track await TrackPlayer.skip(0); // Cautiously reset the seek time, as there might only be a single // item in queue. await TrackPlayer.seekTo(0); // Then play the item await TrackPlayer.play(); } }); return ( ); } // export function ShuffleButton({ fill }: { fill: string}) { // const [isShuffling, setShuffling] = useState(false); // const handlePress = useCallback(() => setShuffling(!isShuffling), [isShuffling, setShuffling]); // return ( // // // // ); // } export function MainButton({ fill }: { fill: string }) { const state = usePlaybackState(); switch (state) { case State.Playing: return ( ); case State.Paused: return ( ); default: return ( ); } }