Start tracking after music finishes

When going to bed I like to listen to music on my Bluetooth headset. I don’t listen to music for a predetermined time, but just turn off the headphones whenever I feel like it.
Currently I then have to additionally use my phone to turn on sleep tracking. Alternatively I could turn on tracking when turning on the music, but then the time I actually listen to music looks like ‘can’t fall asleep time’.
I would therefore propose that if music is currently running on the phone when clicking on start tracking (a quick look in the API shows AudioManager.getActivePlaybackConfigurations should work) the application should ask if tracking should start as soon as playback ends. (Either the playlist is finished or I have turned of the Bluetooth headset)

Good idea. Also, other audio apps that work like music players. Audible, Calm . . . etc.

I am currently enjoying the “Calm” app along with a Hue starter kit, and it really helps. The lights dim as the narrator whispers. But if I fall asleep, even with my wearables on, it wouldn’t start tracking unless I experimented with auto-tracking. Starting when third-party audio stops would be great.

Requested this a long time ago, but via mail I believe.
Especially with sonar this would be great, since sonar will distort the playback.

I am using my phone without Bluetooth equipment for sleeping, only listening to a Audiobook that will stop after a timer hits zero. (shake to restart the timer included)

So, the automatic sleep tracking should look for a active player that is playing and is not paused.
I am not sure, but using the phone state permission should be able to observe this, right?