(2) Create popup window on track long-press in which the track can be added to the end or front of the queue (3) Add Redux counter for added tracks so that the queue is properly updated
26 lines
752 B
TypeScript
26 lines
752 B
TypeScript
import { useEffect, useState } from 'react';
|
|
import TrackPlayer, { usePlaybackState, Track } from 'react-native-track-player';
|
|
import { useTypedSelector } from 'store';
|
|
|
|
/**
|
|
* This hook retrieves the current playing track from TrackPlayer
|
|
*/
|
|
export default function useQueue(): Track[] {
|
|
const state = usePlaybackState();
|
|
const [queue, setQueue] = useState<Track[]>([]);
|
|
const addedTrackCount = useTypedSelector(state => state.player);
|
|
|
|
useEffect(() => {
|
|
TrackPlayer.getQueue().then(setQueue);
|
|
}, [state, addedTrackCount]);
|
|
|
|
return queue;
|
|
}
|
|
|
|
/**
|
|
* Shorthand helper to determine whether a queue exists
|
|
*/
|
|
export function useHasQueue(): boolean {
|
|
const queue = useQueue();
|
|
return !!queue && queue.length > 1;
|
|
} |