From b8408cad9672784c068d1517e1bf6bbeff5ec3b4 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Tue, 14 Oct 2025 01:46:24 -0600 Subject: [PATCH] feat: agregar manejo de errores consecutivos al cargar canciones MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- pages/index.vue | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 0ef447d..c08353b 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -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