doublesymmetry / react-native-track-player

A fully fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!
https://rntp.dev/
Apache License 2.0
3.18k stars 981 forks source link

Add TrackEnd event or fire PlaybackProgressUpdated at the end of the track #2207

Closed SpadarShut closed 6 months ago

SpadarShut commented 7 months ago

What is the need and use case of this feature? I want to implement sleep timer which stops the player at the end of a (current) chapter.

Describe the ideal solution Have a dedicated TrackEnd event.

Describe alternatives you've considered If PlaybackProgressUpdated reliably was called with progress equal to track duration this would also be acceptable.

Additional context Add any other context or screenshots about the feature request here.

How I can Help I'm not skilled in android or ios development, but could do a PR if it could be a JS solution.

lovegaoshi commented 7 months ago

for a JS solution any ActiveTrackChanged and QueueEnded events that were not caused by TP.skip and remote calls are effectively a result of the current track fully played and jumped to the next item in queue. or playback.state changed to stopped but not by TP.stop. or manage your queue outside of RNTP and only keep one track in RNTP; QueueEnded will be what ur looking for.

to properly do in native look for where PlaybackQueueEnded is and take out the queue check.

eg android: emit your event here but without the nextitem = nil check https://github.com/doublesymmetry/react-native-track-player/blob/a0fdd21f77afb4c11cb7062c6665dfd337cef117/android/src/main/java/com/doublesymmetry/trackplayer/service/MusicService.kt#L609

jspizziri commented 6 months ago

At the moment there are no plans to enhance the current sleep timer capabilities beyond their current state.