vamos
This commit is contained in:
@@ -166,9 +166,20 @@ const playTrack = async (track, index) => {
|
||||
// Fetch and preload entire song into memory
|
||||
const encodedName = encodeURIComponent(track.name)
|
||||
const response = await fetch(`/api/music/${encodedName}`)
|
||||
|
||||
// Check for authentication errors
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`)
|
||||
const errorMsg = `HTTP ${response.status}`
|
||||
|
||||
// If auth error, propagate to music store for auth indicator to detect
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
console.warn('[PlayTrack] Authentication error:', response.status)
|
||||
musicStore.error = `${errorMsg}: Unauthorized - Please log in`
|
||||
}
|
||||
|
||||
throw new Error(errorMsg)
|
||||
}
|
||||
|
||||
const blob = await response.blob()
|
||||
const audioUrl = URL.createObjectURL(blob)
|
||||
|
||||
@@ -186,16 +197,22 @@ const playTrack = async (track, index) => {
|
||||
}, { once: true })
|
||||
} catch (error) {
|
||||
console.error('Failed to preload track:', error)
|
||||
|
||||
|
||||
// Mark track as failed
|
||||
failedTracks.value.add(track.name)
|
||||
loadingTrack.value = null
|
||||
|
||||
|
||||
// Don't try fallback streaming if it's an auth error (it will fail too)
|
||||
if (error.message && (error.message.includes('401') || error.message.includes('403'))) {
|
||||
console.warn('[PlayTrack] Skipping fallback due to auth error')
|
||||
return
|
||||
}
|
||||
|
||||
// Try fallback to streaming
|
||||
const encodedName = encodeURIComponent(track.name)
|
||||
audioPlayer.value.src = `/api/music/${encodedName}`
|
||||
audioPlayer.value.load()
|
||||
|
||||
|
||||
// Auto-play when ready (fallback)
|
||||
audioPlayer.value.addEventListener('canplay', () => {
|
||||
loadingTrack.value = null
|
||||
|
||||
Reference in New Issue
Block a user