fix: load audio thmb
This commit is contained in:
@@ -68,7 +68,7 @@ export function FurumiPlayer() {
|
|||||||
Array<{ result_type: string; slug: string; name: string; detail?: string }>
|
Array<{ result_type: string; slug: string; name: string; detail?: string }>
|
||||||
>([])
|
>([])
|
||||||
const [searchOpen, setSearchOpen] = useState(false)
|
const [searchOpen, setSearchOpen] = useState(false)
|
||||||
const searchSelectRef = useRef<(type: string, slug: string) => void>(() => {})
|
const searchSelectRef = useRef<(type: string, slug: string) => void>(() => { })
|
||||||
|
|
||||||
const queueActionsRef = useRef<{
|
const queueActionsRef = useRef<{
|
||||||
playIndex: (i: number) => void
|
playIndex: (i: number) => void
|
||||||
@@ -333,8 +333,18 @@ export function FurumiPlayer() {
|
|||||||
if (i < 0 || i >= q.items.length) return
|
if (i < 0 || i >= q.items.length) return
|
||||||
dispatch(playAtIndex(i))
|
dispatch(playAtIndex(i))
|
||||||
const track = store.getState().queue.items[i]
|
const track = store.getState().queue.items[i]
|
||||||
audio.src = `${API_ROOT}/stream/${track.slug}`
|
// TODO remove after auth refactor
|
||||||
void audio.play().catch(() => {})
|
preloadStream(track.slug).then(response => {
|
||||||
|
console.log('response', response)
|
||||||
|
audio.src = URL.createObjectURL(response?.data)
|
||||||
|
void audio.play().catch(() => { })
|
||||||
|
// Optionally revoke old object URL if needed to avoid memory leaks
|
||||||
|
// if (oldSrc?.startsWith('blob:')) {
|
||||||
|
// URL.revokeObjectURL(oldSrc)
|
||||||
|
// }
|
||||||
|
})
|
||||||
|
// audio.src = `${API_ROOT}/stream/${track.slug}`
|
||||||
|
// void audio.play().catch(() => {})
|
||||||
if (window.history && window.history.replaceState) {
|
if (window.history && window.history.replaceState) {
|
||||||
const url = new URL(window.location.href)
|
const url = new URL(window.location.href)
|
||||||
url.searchParams.set('t', track.slug)
|
url.searchParams.set('t', track.slug)
|
||||||
@@ -550,28 +560,28 @@ export function FurumiPlayer() {
|
|||||||
const clearQueueBtn = document.getElementById('btnClearQueue')
|
const clearQueueBtn = document.getElementById('btnClearQueue')
|
||||||
clearQueueBtn?.addEventListener('click', () => clearQueuePlayback())
|
clearQueueBtn?.addEventListener('click', () => clearQueuePlayback())
|
||||||
|
|
||||||
;(async () => {
|
; (async () => {
|
||||||
const url = new URL(window.location.href)
|
const url = new URL(window.location.href)
|
||||||
const urlSlug = url.searchParams.get('t')
|
const urlSlug = url.searchParams.get('t')
|
||||||
if (urlSlug) {
|
if (urlSlug) {
|
||||||
try {
|
try {
|
||||||
const { detail } = await dispatch(fetchTrackDetail(urlSlug)).unwrap()
|
const { detail } = await dispatch(fetchTrackDetail(urlSlug)).unwrap()
|
||||||
addTrackToQueue(
|
addTrackToQueue(
|
||||||
{
|
{
|
||||||
slug: detail.slug,
|
slug: detail.slug,
|
||||||
title: detail.title,
|
title: detail.title,
|
||||||
artist: detail.artist_name,
|
artist: detail.artist_name,
|
||||||
album_slug: detail.album_slug,
|
album_slug: detail.album_slug,
|
||||||
duration: detail.duration_secs,
|
duration: detail.duration_secs,
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
} catch {
|
} catch {
|
||||||
// fetchTrackDetail rejected — track not found or error
|
// fetchTrackDetail rejected — track not found or error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
void showArtists()
|
||||||
void showArtists()
|
})()
|
||||||
})()
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
queueActionsRef.current = null
|
queueActionsRef.current = null
|
||||||
|
|||||||
@@ -44,6 +44,6 @@ export async function getTrackInfo(trackSlug: string): Promise<TrackDetail | nul
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function preloadStream(trackSlug: string) {
|
export async function preloadStream(trackSlug: string) {
|
||||||
await furumiApi.get(`/stream/${trackSlug}`, { responseType: 'arraybuffer' }).catch(() => null)
|
return await furumiApi.get(`/stream/${trackSlug}`, { responseType: 'blob' }).catch(() => null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user