mirror of
https://github.com/janishutz/MusicPlayer.git
synced 2026-09-10 14:25:24 +02:00
feat: basic player commands
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
import type {
|
||||
Song
|
||||
} from '@/ts/dtype/playlist';
|
||||
import {
|
||||
queue
|
||||
} from '../state';
|
||||
|
||||
export const addSongList = ( songs: Song[] ) => {
|
||||
for ( const song of songs ) {
|
||||
queue.value.push( song );
|
||||
}
|
||||
};
|
||||
|
||||
export const shuffleList = () => {};
|
||||
@@ -0,0 +1,36 @@
|
||||
import {
|
||||
currentSource,
|
||||
queue,
|
||||
queueIdx,
|
||||
repeat,
|
||||
sources
|
||||
} from '../state';
|
||||
import {
|
||||
startTracking,
|
||||
stopTracking
|
||||
} from '../status-tracking';
|
||||
|
||||
/**
|
||||
* Play a song at the given index of the queue. Wraps to 0 and end if index below 0 or above end
|
||||
* @param idx - The index in the queue to play at
|
||||
*/
|
||||
export const playIndex = async ( idx: number ) => {
|
||||
if ( idx >= queue.value.length ) {
|
||||
idx = repeat.value === 'all' ? 0 : -1;
|
||||
} else if ( idx < 0 ) {
|
||||
idx = repeat.value === 'all' ? queue.value.length - 1 : -1;
|
||||
}
|
||||
|
||||
if ( idx < 0 ) return false;
|
||||
|
||||
sources[currentSource.value]?.stop();
|
||||
stopTracking();
|
||||
|
||||
const nextSong = queue.value[ idx ]!;
|
||||
|
||||
queueIdx.value = idx;
|
||||
currentSource.value = nextSong.source;
|
||||
sources[currentSource.value]?.playSong( nextSong.identifier );
|
||||
|
||||
startTracking();
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
// TODO: If local files contained, prompt user to select files, then associate based on file names
|
||||
export const load = () => {};
|
||||
Reference in New Issue
Block a user