add cards & tracks
All checks were successful
Deploy App / build (push) Successful in 1m13s
Deploy App / deploy (push) Successful in 15s

This commit is contained in:
valere
2025-10-02 00:38:54 +02:00
parent 8c1290beae
commit 43b1a11027
11 changed files with 474 additions and 43 deletions

57
app/store/player.ts Normal file
View File

@@ -0,0 +1,57 @@
// ~/store/player.ts
import { defineStore } from 'pinia'
import type { Track } from '~/types/types'
export const usePlayerStore = defineStore('player', {
state: () => ({
currentTrack: null as Track | null,
isPlaying: false,
position: 0,
audio: null as HTMLAudioElement | null,
}),
actions: {
setTrack(track: Track) {
this.currentTrack = track
if (!this.audio) this.audio = new Audio(this.getCompilationUrlFromTrack(track))
else this.audio.src = this.getCompilationUrlFromTrack(track)
// Commencer à start secondes
this.audio.currentTime = track.start || 0
},
playTrack(track?: Track) {
if (track) this.setTrack(track)
if (!this.currentTrack || !this.audio) return
this.audio.play()
this.isPlaying = true
},
pauseTrack() {
if (this.audio) this.audio.pause()
this.isPlaying = false
},
togglePlay(track?: Track) {
if (track && (!this.currentTrack || track.id !== this.currentTrack.id)) {
this.playTrack(track)
} else {
this.isPlaying ? this.pauseTrack() : this.playTrack()
}
},
setPosition(time: number) {
if (this.audio) this.audio.currentTime = time
this.position = time
},
},
getters: {
getCurrentTrack: (state) => state.currentTrack,
getPlaying: (state) => state.isPlaying,
getCompilationUrlFromTrack: (state) => {
return (track: Track) => `https://files.erudi.fr/evilspins/${track.compilationId}.mp3`
}
},
})