Skip to content

Commit 4bb6524

Browse files
committed
feat(palyer): get metadata in display track
1 parent ea1e2ca commit 4bb6524

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1+
import type { TrackMetadata } from '@flow/core'
2+
import { getTrackMetadataAsync } from '@nodefinity/react-native-music-library'
3+
import { useEffect, useState } from 'react'
14
import { usePlayerStore } from '../playerStore'
25

3-
// eslint-disable-next-line react-hooks-extra/no-unnecessary-use-prefix
46
export function useDisplayTrack() {
57
const queue = usePlayerStore.use.queue()
68
const currentIndex = usePlayerStore.use.currentIndex()
79

8-
return queue[currentIndex] || undefined
10+
const [trackWithMetadata, setTrackWithMetadata] = useState<TrackMetadata | undefined>(undefined)
11+
12+
const currentTrack = queue[currentIndex]
13+
14+
useEffect(() => {
15+
if (!currentTrack)
16+
return
17+
18+
const fetchMetadata = async () => {
19+
const metadata = await getTrackMetadataAsync(currentTrack.id)
20+
setTrackWithMetadata({ ...currentTrack, ...metadata })
21+
}
22+
23+
fetchMetadata()
24+
}, [currentTrack])
25+
26+
return trackWithMetadata
927
}

0 commit comments

Comments
 (0)