mirror of
https://github.com/Jellify-Music/App.git
synced 2026-03-09 05:30:22 -05:00
play next and add to queue changes
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import { isEmpty } from "lodash";
|
||||
import { QueuingType } from "../../enums/queuing-type";
|
||||
import { JellifyTrack } from "../../types/JellifyTrack";
|
||||
import { getActiveTrackIndex } from "react-native-track-player/lib/src/trackPlayer";
|
||||
|
||||
/**
|
||||
* Finds and returns the index of the player queue to insert additional tracks into
|
||||
* @param playQueue The current player queue
|
||||
* @returns The index to insert songs to play next at
|
||||
*/
|
||||
export const findPlayNextIndexStart = (playQueue: JellifyTrack[]) => {
|
||||
if (playQueue.length > 0)
|
||||
return 1
|
||||
export const findPlayNextIndexStart = async (playQueue: JellifyTrack[]) => {
|
||||
if (isEmpty(playQueue))
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
return (await getActiveTrackIndex())! + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -19,10 +20,18 @@ export const findPlayNextIndexStart = (playQueue: JellifyTrack[]) => {
|
||||
* @param playQueue The current player queue
|
||||
* @returns The index to insert songs to add to the user queue
|
||||
*/
|
||||
export const findPlayQueueIndexStart = (playQueue: JellifyTrack[]) => {
|
||||
export const findPlayQueueIndexStart = async (playQueue: JellifyTrack[]) => {
|
||||
|
||||
if (isEmpty(playQueue))
|
||||
return 0;
|
||||
|
||||
return playQueue.findIndex(queuedTrack => queuedTrack.QueuingType === QueuingType.FromSelection);
|
||||
const activeIndex = await getActiveTrackIndex();
|
||||
|
||||
if (playQueue.findIndex(track => track.QueuingType === QueuingType.FromSelection) === -1)
|
||||
return activeIndex! + 1
|
||||
|
||||
return playQueue.findIndex((queuedTrack, index) =>
|
||||
queuedTrack.QueuingType === QueuingType.FromSelection &&
|
||||
index > activeIndex!
|
||||
);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { JellifyTrack } from "../types/JellifyTrack";
|
||||
import { storage } from "../constants/storage";
|
||||
import { MMKVStorageKeys } from "../enums/mmkv-storage-keys";
|
||||
import { findPlayNextIndexStart, findPlayQueueIndexStart } from "./helpers/index";
|
||||
import TrackPlayer, { Event, Progress, State, usePlaybackState, useProgress, useTrackPlayerEvents } from "react-native-track-player";
|
||||
import TrackPlayer, { Event, Progress, State, Track, usePlaybackState, useProgress, useTrackPlayerEvents } from "react-native-track-player";
|
||||
import _, { isEqual, isUndefined } from "lodash";
|
||||
import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { handlePlaybackProgressUpdated, handlePlaybackState } from "./handlers";
|
||||
@@ -75,7 +75,7 @@ const PlayerContextInitializer = () => {
|
||||
}
|
||||
|
||||
const addToQueue = async (tracks: JellifyTrack[]) => {
|
||||
const insertIndex = findPlayQueueIndexStart(queue);
|
||||
const insertIndex = await findPlayQueueIndexStart(queue);
|
||||
console.debug(`Adding ${tracks.length} to queue at index ${insertIndex}`)
|
||||
|
||||
await TrackPlayer.add(tracks, insertIndex);
|
||||
@@ -86,7 +86,7 @@ const PlayerContextInitializer = () => {
|
||||
}
|
||||
|
||||
const addToNext = async (tracks: JellifyTrack[]) => {
|
||||
const insertIndex = findPlayNextIndexStart(queue);
|
||||
const insertIndex = await findPlayNextIndexStart(queue);
|
||||
|
||||
console.debug(`Adding ${tracks.length} to queue at index ${insertIndex}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user