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.2k stars 984 forks source link

fix(android): Allow setting grace period before stopForeground #2164

Closed dcvz closed 9 months ago

dcvz commented 9 months ago

This PR adds a configurable grace period - a delay before we attempt to set our service to not be in foreground mode, allowing users a chance to do player actions that might refrain us from deciding to go out of foreground state. Defaults to five seconds.

Context: At the moment on Android as soon as we transition back to idle/stop/error we immediately set our service as not being in the foreground state (setting yourself as not in foreground is good practice). In the use of RNTP where everyone's needs are different, a user might still want to enqueue some kind of playback action once they realize the queue is over, an error has happened, etc. For example, once a user's queue ends, they may want to create a whole new queue of related music.

Immediately setting ourselves as not in foreground state may give the OS a chance to turn off network chips, or kill the service which may result in errors if you try to do any network loading (i.e. playing a remote track) after that as happens on #2159.

elliotdickison commented 9 months ago

This will be particularly helpful in the workaround for #1845