Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | 2x | import { AudioPlayer } from "hooks"; import { ITrack } from "types/spotify"; export function getAudioPlayerPreviousPlayableTrack( audioPlayer: AudioPlayer ): ITrack | null { const allTracks = audioPlayer.allTracks; const currentTrackIndex = allTracks.findIndex( ({ preview_url }) => preview_url === audioPlayer.src ); let previousTrackIndex = (currentTrackIndex ?? -1) - 1; let previousTrack: ITrack | null = null; while (previousTrackIndex >= 0) { const previewUrl = allTracks[previousTrackIndex]?.preview_url; Iif (previewUrl) { previousTrack = allTracks[previousTrackIndex]; break; } previousTrackIndex--; } return previousTrack; } |