feat: agregar manejo de errores consecutivos al cargar canciones
- Agregar contador de errores consecutivos - Detener reproducción después de 2 errores consecutivos - Mostrar toast de error cuando se alcanza el límite - Resetear contador cuando una canción carga exitosamente - Continuar con la siguiente canción en el primer error
This commit is contained in:
@@ -63,6 +63,7 @@ definePageMeta({
|
||||
import { ref, onMounted, onUnmounted, computed, watch } from 'vue'
|
||||
import { useLocalStorage } from '@vueuse/core'
|
||||
import { useMusicStore } from '~/stores/music'
|
||||
import { useToastStore } from '~/stores/toast'
|
||||
|
||||
// Import components
|
||||
import AuroraBackground from '~/components/AuroraBackground.client.vue'
|
||||
@@ -72,6 +73,7 @@ import MusicControls from '~/components/MusicControls.client.vue'
|
||||
|
||||
// Store
|
||||
const musicStore = useMusicStore()
|
||||
const toastStore = useToastStore()
|
||||
|
||||
// Reactive state
|
||||
const tracks = computed(() => musicStore.tracks)
|
||||
@@ -96,6 +98,9 @@ const shuffledIndices = ref([])
|
||||
// Search state
|
||||
const searchQuery = ref('')
|
||||
|
||||
// Error tracking
|
||||
const consecutiveErrors = ref(0)
|
||||
|
||||
// Refs
|
||||
const audioPlayer = ref(null)
|
||||
|
||||
@@ -363,7 +368,21 @@ const onAudioError = (error) => {
|
||||
// Clear loading state
|
||||
loadingTrack.value = null
|
||||
|
||||
// Try next track if current fails
|
||||
// Increment consecutive error counter
|
||||
consecutiveErrors.value++
|
||||
|
||||
// Check if we've hit 2 consecutive errors
|
||||
if (consecutiveErrors.value >= 2) {
|
||||
// Stop trying and show error toast
|
||||
toastStore.error('No se pudieron cargar 2 canciones consecutivas. Reproducción detenida.', 4000)
|
||||
isPlaying.value = false
|
||||
consecutiveErrors.value = 0 // Reset counter
|
||||
console.warn('[AudioError] Stopped playback after 2 consecutive failures')
|
||||
return
|
||||
}
|
||||
|
||||
// Try next track if we haven't hit the limit
|
||||
console.log(`[AudioError] Attempting next track (consecutive errors: ${consecutiveErrors.value})`)
|
||||
setTimeout(() => {
|
||||
nextTrack()
|
||||
}, 1000) // Small delay before trying next track
|
||||
@@ -381,7 +400,8 @@ const onTrackEnded = () => {
|
||||
}
|
||||
|
||||
const onCanPlay = () => {
|
||||
// Track is ready to play
|
||||
// Track is ready to play - reset error counter
|
||||
consecutiveErrors.value = 0
|
||||
}
|
||||
|
||||
// Watchers
|
||||
|
||||
Reference in New Issue
Block a user