If I fire this while a song is playing:
TrackPlayer.getCurrentTrack(id,function(string) {
console.log(string)
})
I get string = null. I'm hoping to use this feature so that if the app does close in the background while the player keeps going, when resuming the app I'm able to restore the state and show the currently playing song in the UI. From the docs, it seems like it's expected to return the track ID? Would be cool if it returned the whole object, including artist name, song title, artwork, etc.
Are you using load or add to load the tracks? Which player are you using (ExoPlayer, native Android player, etc)?
For now I get rid of the whole object, keeping only the important information. I don't know if I should keep it, it can definitely be helpful for changing the player (from a local one to a Chromecast device). What do you think? The only reason to dispose the object is to reduce a bit of memory usage.
I'm using load to play each track; I'm using add to line up the future tracks. This is with ExoPlayer.
When you say remove the whole object, which are you referring to?
Was messing around with this today because occasionally my React instance gets misaligned with the player and shows the wrong currently playing song. Would be rad if I could somehow sync them, but no matter what I do this keeps returning "null." I was able to add a bit of a console log and convert currentTrack to a string so that I could output its value, and I do indeed see it increment from 0 to 1 to 2, etc. Dunno if something's maybe wrong with "queue.get"?
Any tips on how I can get this to return the currently-playing song object?
At the moment getCurrentTrack returns the id of the track (which you're supposed to provide; mandatory according to the docs). It could be changed to provide the whole object but at the moment there's no way of doing this.
This is returning null on Android for me:
TrackPlayer.getCurrentTrack((track) => {
console.log(track)
})
Okay, resolved this issue. It's because I was passing an integer instead of a string as the track id.
Most helpful comment
Okay, resolved this issue. It's because I was passing an integer instead of a string as the track id.