react-native-track-player icon indicating copy to clipboard operation
react-native-track-player copied to clipboard

[Android] TrackPlayer.load doesn't pass correct event data

Open jspizziri opened this issue 1 year ago • 9 comments

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.

jspizziri avatar Nov 21 '24 15:11 jspizziri

@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).

jspizziri avatar Nov 21 '24 15:11 jspizziri

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.

github-actions[bot] avatar Feb 20 '25 02:02 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Feb 27 '25 02:02 github-actions[bot]

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.

github-actions[bot] avatar May 29 '25 02:05 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Jun 05 '25 02:06 github-actions[bot]

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.

github-actions[bot] avatar Sep 05 '25 02:09 github-actions[bot]

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.

jspizziri avatar Sep 18 '25 20:09 jspizziri

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 avatar Sep 19 '25 14:09 puckey

@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).

jspizziri avatar Sep 19 '25 16:09 jspizziri