Files
jellyfin-audio-player/src/utility/useQueue.ts
Lei Nelissen c88158cf16 (1) Play whole album when selecting a single track
(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
2020-08-28 16:28:49 +02:00

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;
}