I would like my app to be notified whenever media starts playing on an Android device. I can't seem to find any system broadcast that is sent out when this happens. I know I can check with audiomanager.isMusicActive() but this would require me to poll constantly.
I also know you can request audioFocus and then listen for when you lose focus, but I don't necessarily want to request audio focus either!
You could use AudioManager#registerAudioPlaybackCallback() to register a callback that will be notified on playback events.
And then you can register the callback somewhere in your application.
I am not sure if AudioAttributes.getUsage() is the correct method for you, maybe you would like to use AudioAttributes.getContentType() to check for
CONTENT_TYPE_MUSICinstead.