Music Active Trigger

Post your feature requets for new triggers, conditions, actions and other improvements.

Moderator: Martin

Locked
ZSasha
Posts: 103
Joined: 11 Oct 2013 03:48

Music Active Trigger

Post by ZSasha » 26 Mar 2014 20:32

Hi Martin,

we have "Music Active" condition, would it be possible to add "music active" trigger?
To activate a flow once [any] music is playing (no matter what player/application)

Thanks.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Music Active Trigger

Post by Martin » 26 Mar 2014 20:44

Hi,

I have not yet found an API in Android that allows to detect this event and I don't like to fall back to a polling mechanism at the moment.
Some music players send broadcast intents you can capture with trigger General Broadcast but not all media players do this as far as I know.

Regards,
Martin

User avatar
mbirth
Posts: 80
Joined: 17 Mar 2016 00:02
Location: Berlin, Germany
Contact:

Re: Music Active Trigger

Post by mbirth » 23 Mar 2016 15:02

You can watch for a general broadcast "com.android.music.playstatechanged". This is fired whenever some (compatible) app starts or stops playing music.

Then read out the new state via the "playing" extra:

Code: Select all

isPlaying = getBoolean("playing", false);
(If a song is playing, there are probably more extras, e.g. song, album, artist, etc.. See here.)

This works for Play Music and Pocket Casts for me. Didn't test with other apps.

P.S.: Other apps seem to use different broadcasts, see here for a list.
BlackBerry KEY2, Android 8.1.0

Locked