react-native-track-player: [Only in IOS background Mode] not able to fetch next song from server after `playback-queue-ended` in IOS background mode
Hey Folks,
I am trying to fetch the next song from the server when playback-queue-ended invoked.
It’s working fine with Android (both foreground and background) and IOS (only in the foreground). In the case of the IOS background, it’s not working at all.
though, It’s working perfectly fine with the IOS simulator.
Note: I have read somewhere in issues, that is not possible because of limited amount of time before the OS kills the app but that’s not true because the same functionality is already available with one more package react-native-music-control but unfortunately I can’t use it because that package is not maintained anymore and they recommended to use only this react-native-track-player package.
You’re running into an issue with iOS… once playback stops you’ll have a limited amount of time before the OS kills the app. Your fetch for a new track must not be working effectively and the OS is shutting down the app. possibly the RN thread is also sleeping on you.
To Reproduce
- write code to fetch next song when
playback-queue-ended - Put your IOS App in background
- keep listening to the first song
- And when
playback-queue-endedit should fetch and play next song from the server but it’s failed
Environment:
System:
OS: macOS 10.15.2
Binaries:
Node: 13.5.0 - /usr/local/bin/node
npm: 6.13.4 - /usr/local/bin/npm
SDKs:
iOS SDK:
Platforms: iOS 13.2
IDEs:
Xcode: 11.3/11C29 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.2 => 0.61.2
npmGlobalPackages:
react-native-cli: 2.0.1
What react-native-track-player version are you using?
2.0.0-rc13
Code
TrackPlayer.addEventListener(Event.PlaybackQueueEnded, async event => {
----FETCH NEXT SONG FROM SERVER HERE-----
});
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 24 (10 by maintainers)
Hey @shuvo0074
Try this one:
Here
isAppActiveisAppStatefrom react-nativePlease let me know if you need more information
Thanks
I am now remembering, I think I used a hack to get around this in my production app.
In that app, I add a special track that is just 5-10 seconds of silence, after my normal track.
That silence track keeps the app alive in the background while the next track is fetched.
In this case I use
playback-track-changedto detect when to do this, instead ofplayback-queue-ended.