File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
packages/player/src/hooks Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 1+ import type { TrackMetadata } from '@flow/core'
2+ import { getTrackMetadataAsync } from '@nodefinity/react-native-music-library'
3+ import { useEffect , useState } from 'react'
14import { usePlayerStore } from '../playerStore'
25
3- // eslint-disable-next-line react-hooks-extra/no-unnecessary-use-prefix
46export 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}
You can’t perform that action at this time.
0 commit comments