feat: agregar manejo de errores consecutivos al cargar canciones
All checks were successful
build-and-deploy / build (push) Successful in 23s
build-and-deploy / deploy (push) Successful in 3s

- 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:
2025-10-14 01:46:24 -06:00
parent 1a5dbbbcb2
commit b8408cad96

View File

@@ -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)
@@ -354,16 +359,30 @@ const onLoadedMetadata = () => {
const onAudioError = (error) => {
console.error('Audio error:', error)
console.error('Failed to load:', currentTrack.value?.name)
// Mark track as failed
if (currentTrack.value) {
failedTracks.value.add(currentTrack.value.name)
}
// 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