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 { ref, onMounted, onUnmounted, computed, watch } from 'vue'
|
||||||
import { useLocalStorage } from '@vueuse/core'
|
import { useLocalStorage } from '@vueuse/core'
|
||||||
import { useMusicStore } from '~/stores/music'
|
import { useMusicStore } from '~/stores/music'
|
||||||
|
import { useToastStore } from '~/stores/toast'
|
||||||
|
|
||||||
// Import components
|
// Import components
|
||||||
import AuroraBackground from '~/components/AuroraBackground.client.vue'
|
import AuroraBackground from '~/components/AuroraBackground.client.vue'
|
||||||
@@ -72,6 +73,7 @@ import MusicControls from '~/components/MusicControls.client.vue'
|
|||||||
|
|
||||||
// Store
|
// Store
|
||||||
const musicStore = useMusicStore()
|
const musicStore = useMusicStore()
|
||||||
|
const toastStore = useToastStore()
|
||||||
|
|
||||||
// Reactive state
|
// Reactive state
|
||||||
const tracks = computed(() => musicStore.tracks)
|
const tracks = computed(() => musicStore.tracks)
|
||||||
@@ -96,6 +98,9 @@ const shuffledIndices = ref([])
|
|||||||
// Search state
|
// Search state
|
||||||
const searchQuery = ref('')
|
const searchQuery = ref('')
|
||||||
|
|
||||||
|
// Error tracking
|
||||||
|
const consecutiveErrors = ref(0)
|
||||||
|
|
||||||
// Refs
|
// Refs
|
||||||
const audioPlayer = ref(null)
|
const audioPlayer = ref(null)
|
||||||
|
|
||||||
@@ -354,16 +359,30 @@ const onLoadedMetadata = () => {
|
|||||||
const onAudioError = (error) => {
|
const onAudioError = (error) => {
|
||||||
console.error('Audio error:', error)
|
console.error('Audio error:', error)
|
||||||
console.error('Failed to load:', currentTrack.value?.name)
|
console.error('Failed to load:', currentTrack.value?.name)
|
||||||
|
|
||||||
// Mark track as failed
|
// Mark track as failed
|
||||||
if (currentTrack.value) {
|
if (currentTrack.value) {
|
||||||
failedTracks.value.add(currentTrack.value.name)
|
failedTracks.value.add(currentTrack.value.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear loading state
|
// Clear loading state
|
||||||
loadingTrack.value = null
|
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(() => {
|
setTimeout(() => {
|
||||||
nextTrack()
|
nextTrack()
|
||||||
}, 1000) // Small delay before trying next track
|
}, 1000) // Small delay before trying next track
|
||||||
@@ -381,7 +400,8 @@ const onTrackEnded = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onCanPlay = () => {
|
const onCanPlay = () => {
|
||||||
// Track is ready to play
|
// Track is ready to play - reset error counter
|
||||||
|
consecutiveErrors.value = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Watchers
|
// Watchers
|
||||||
|
|||||||
Reference in New Issue
Block a user