Spaces:
Running
Running
| import { defineStore } from 'pinia' | |
| export const useVideoStore = defineStore('video', { | |
| state: () => ({ | |
| videos: [], | |
| selectedVideo: null, | |
| defaultPath: 'C:\\Users\\antoi\\Documents\\Work_Learn\\Stage-Rennes\\RepositoryFootballVision\\SportDETR\\data\\football\\raw', | |
| // defaultPath: '\\\\10.35.51.152\\Biomeca\\Projets\\25_EVA2PERF_M2_AntoineVerdon\\RepositoryFootballVision\\SportDETR\\data\\football\\raw', | |
| currentTime: 0, | |
| isPlaying: false, | |
| duration: 0, | |
| fps: 25, // FPS par défaut changé à 25 | |
| // Vidéo par défaut depuis les assets | |
| defaultVideo: null, | |
| isInitialized: false | |
| }), | |
| actions: { | |
| // Initialiser avec une vidéo par défaut si aucune n'est sélectionnée | |
| async initialize() { | |
| if (!this.isInitialized && !this.selectedVideo) { | |
| // Essayer de charger une vidéo par défaut depuis les assets | |
| try { | |
| const defaultVideoPath = require('@/assets/football.mp4') | |
| this.defaultVideo = { | |
| name: 'football', | |
| path: defaultVideoPath, | |
| type: 'video/mp4', | |
| isDefault: true | |
| } | |
| // Ne pas définir automatiquement comme selectedVideo, laisser l'utilisateur choisir | |
| } catch (error) { | |
| console.log('Aucune vidéo par défaut disponible dans les assets') | |
| } | |
| this.isInitialized = true | |
| } | |
| }, | |
| setVideos(videos) { | |
| this.videos = videos | |
| }, | |
| async setSelectedVideo(video) { | |
| this.selectedVideo = video | |
| }, | |
| setCurrentTime(time) { | |
| this.currentTime = time | |
| }, | |
| setIsPlaying(isPlaying) { | |
| this.isPlaying = isPlaying | |
| }, | |
| setDuration(duration) { | |
| this.duration = duration | |
| }, | |
| setFps(fps) { | |
| this.fps = fps | |
| console.log('FPS défini à:', fps) | |
| }, | |
| async loadVideosFromFolder() { | |
| // DÉSACTIVÉ - pas de chargement de dossier externe | |
| this.videos = [] | |
| return [] | |
| }, | |
| async loadVideoMetadata(videoPath) { | |
| return new Promise((resolve, reject) => { | |
| const tempVideo = document.createElement('video') | |
| tempVideo.src = videoPath | |
| tempVideo.crossOrigin = 'anonymous' | |
| tempVideo.addEventListener('loadedmetadata', () => { | |
| this.duration = tempVideo.duration | |
| resolve({ | |
| duration: tempVideo.duration, | |
| videoElement: tempVideo | |
| }) | |
| }) | |
| tempVideo.addEventListener('error', (error) => { | |
| console.error('Erreur lors du chargement de la vidéo:', error) | |
| reject(error) | |
| }) | |
| }) | |
| }, | |
| updateProgressBar(time) { | |
| this.currentTime = time | |
| this.emitTimeUpdate(time) | |
| }, | |
| emitTimeUpdate(time) { | |
| this.currentTime = time | |
| } | |
| } | |
| }) |