[Android] TrackPlayer.load doesn't pass correct event data
Describe the Bug
On Android, the TrackPlayer.load(...) call will trigger a PlaybackActiveTrackChanged, however if there was a previous item playing, lastTrack on the emitted event is always undefined. On iOS lastTrack is emitted as expected in this scenario.
Steps To Reproduce
Use load to add tracks and observe the PlaybackActiveTrackChanged events lastTrack property.
EDIT: might only happen when transitioning between downloaded and undownloaded tracks.
Code To Reproduce N/A
Replicable on Example App?
I'll be verifying this over the next few days.
Environment Info:
Google Pixel 6a
How I can Help
I intend to fix this, but I want it to be tracked in git.
@puckey I'm going to fix this soon. But before I do, I just wanted to verify that you agreethat Android should behave like iOS (load should always emit a lastTrack/lastPosition if it exists).
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.
This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.
So there's actually something more fundamental going on here. I have it "more fixed" but not completely. There's basically a fundamental issue of no "load" equivalent in exoPlayer. The only way to load things is to add them to the playlist and then move on. This causes our "queue" and the exoPlayer "playlist" to drift out of sync over time.
Perhaps load needs to be rethought so that it really is inserting something at the "next" position of the queue and then transitioning directly to it.
I've implemented the above approach in https://github.com/doublesymmetry/react-native-track-player/pull/2519 as it makes the most sense to me. It would need to be implemented in iOS and web as well to maintain consistency.
See https://github.com/puckey/react-native-track-player/commit/328943e9b5b6400aebfb8401fbae2c1c12c38ad4 to get TrackPlayer.load working on Android. Note that I haven't checked if this fixes PlaybackActiveTrackChanged also
@puckey I tested your commit and it seems to work well. I've added it to my exist PR for Android Auto given there are other related improvements I have in there (specifically the direct usage of MediaItem's that are emitted from ExoPlayer).