checking if music is playing?

1,566 views
Skip to first unread message

Phil

unread,
Apr 21, 2016, 11:49:10 AM4/21/16
to Tasker

My bluetooth car stereo has this annoying feature that auto-plays music.  However, it's somewhat random and it starts (or not) at random times-- could be immediately, could be 1 minute after the BT connection or sometimes longer.  I have no idea how/when/why... it's apparently voodoo and there is no way for me to disable that "feature" on my car stereo.  For instance sometimes I get in my car drive 5 minutes to get gas without it auto-playing. I stop the engine, fill up, get back in my car several minutes later and it starts auto-playing!

The Tasker media/stop command will stop it if it's playing but since I don't know when it will occur it's hard to time.  Also, it seems to override the media volume (VOLM) since I had my car task setting it to 0 but when I displayed the value immediately after setting it printed 11.

I see there is an "is music playing?" Tasker plugin for $0.99.

I was hesitant to try it since it was last updated in 2013 and I'm running Marshmallow (unrooted) but when I tried it, as expected it didn't work.  I've tried a couple of other plugins but nothing seems to work for my stereo. 

I'd really like to be able to create a profile with the state that music is playing and be able to decide what to do at that time-- so for instance, based on that + some other conditions, I could stop it immediately.  
I have a much larger profile/tasks that ultimately rely on whether music is playing so I'd like to be able to detect this.  Under normal circumstances, if I start Spotify, for instance Tasker knows it's playing and I can get all of the track data for it but when my stereo does the same Tasker seems oblivious to it until the next track starts (since Spotify broadcasts an intent).  However, I want to know that info immediately and not rely on the next track.


Thanks,

Phil

Wayne Longford

unread,
Apr 21, 2016, 6:55:58 PM4/21/16
to Tasker
To monitor the playback state of Spotify you can use this intent:

com.spotify.music.playbackstatechanged

Then in the enter task you have access to the extra in the form of a local variable %playing which will be either true/false.

If you save %playing to a global variable, you can then use it in another profile to monitor the state of Spotify playback.

Phil

unread,
Apr 21, 2016, 11:10:35 PM4/21/16
to Tasker


Thanks for the reply Wayne. I already have a profile that reacts to that intent's broadcast and uses it accordingly.  However, I've found a way to reproduce the issue w/o my magical car stereo.  If Spotify isn't running and you have a task that does a media->media control->play [simulated] (app: spotify) it does begin playing the last track I was listening to and even after the next track begins that intent is not broadcast.  If I repeat that when Spotify was already open the intent is sent.  My car stereo appears to be sending the equivalent of "play [simulated]". So when this is the case, that Spotify isn't running (even though it appears in the notification area) I'd like to be able to detect that music is playing since that intent alone can't be relied on.

Phil

unread,
Apr 22, 2016, 1:41:38 AM4/22/16
to Tasker
I think I have found a hacky solution using AutoNotification.  When Spotify is started in it's half-baked way (ie. the app isn't open so it's not sending intents but music is playing) it appears to still present a widget in the notification area (containing image art, track info, etc....).  So using AutoNotification I can filter on the app ("spotify") and setup an "event" profile in Tasker using the AutoNotification plugin.  When that spotify event is received  and if my %MusicIsPlaying variable is "no" (since if I do start spotify and hit play I set that var to "yes") the invoked task sends the media->media control->stop command.

I haven't actually tried this in my car yet, but using the workflow I mentioned in my last message it seemed to work for me.  It would be so awesome if this actually works because it's been really frustrating and annoying never knowing exactly what's going to happen when I start driving.

Richard Wallace

unread,
Apr 22, 2016, 10:08:53 AM4/22/16
to Tasker
You can use Java to return if music is playing. So far it has worked with any music playing app I have used.

getMusicPlaying (122)
A1: Java Function [ Return:manage Class Or Object:CONTEXT Function:getSystemService
{Audio} (String) Param:audio Param: Param: Param: Param: Param: Param: ]
A2: Java Function [ Return:%playing Class Or Object:manage Function:isMusicActive {boolean} () Param: Param: Param: Param: Param: Param: Param: ]
A3: Flash [ Text:%playing Long:Off ]


Team this with a BT connected profile for your car and then fire this task, perhaps with a small wait before to allow BT connection to finish up?

Phil

unread,
Apr 22, 2016, 1:50:14 PM4/22/16
to Tasker
Thanks.  Rookie question, I'm sure: how can I import that task description into a task?  I know if I long-click the "task" tab I can import an xml file and I know you can export xml or a description but I can't seem to import the description.  My searches didn't turn up anything useful, all of the matches seemed to refer to xml.

Rich D

unread,
Apr 24, 2016, 8:26:54 AM4/24/16
to Tasker Google Groups Post


> Thanks.  Rookie question, I'm sure: how can I import that task description into a task?

Not possible.  That is what the XML is for.

Phil

unread,
Apr 24, 2016, 11:32:30 PM4/24/16
to Tasker

I was afraid of that.  Not sure why it's impossible-- if Tasker can output the description why can't it import it?  I generally don't have an issue following a description and translating it into actions but I haven't done so with the 'code' actions, so I wasn't sure how to take what Richard provided and reconstruct it within Tasker.

PC

unread,
Apr 25, 2016, 12:48:55 AM4/25/16
to Tasker
Here you go.  Probably not the same as the above, but I just got this and am using it now.  Fairly self-explanatory.  This is just a task.

Enjoy!
Java_Music_Playing_.tsk.xml

Phil

unread,
Apr 26, 2016, 10:19:17 PM4/26/16
to Tasker

Thanks PC!  Certainly saved me the time from trying to decipher and convert the description-to-xml.  It seemed to work in my playing/not playing states so hopefully it will behave when I actually use it.  I sometimes see things work great when running as a test (with the task/play button) that don't behave as well when run from a profile.  

Phil

unread,
Apr 27, 2016, 1:02:17 AM4/27/16
to Tasker
So far the task works but not sure what profile should invoke it to set a global variable (so that my car profile can conditionally check for it) as opposed from the car profile invoking it (via performTask) repeatedly to check.

I suppose if Bluetooth is connected I could activate a timed profile that checks every 5 seconds and deactivates when Bluetooth disconnects. Is there a better option?

PC

unread,
Apr 28, 2016, 1:27:36 PM4/28/16
to Tasker
I would use 30 seconds instead, just so the task isn't running so often.  It strikes a good balance between power usage by BT being on, and not running too often.
Message has been deleted

Mihir Gohad

unread,
Apr 26, 2017, 11:21:22 AM4/26/17
to Tasker
Can't import this file on my tasker. It is not able to see the file.

Mihir Gohad

unread,
Apr 26, 2017, 11:24:34 AM4/26/17
to Tasker
It says "Tasker can't handle the content 

Mihir Gohad

unread,
Apr 26, 2017, 11:40:46 AM4/26/17
to Tasker

Robert Kedves

unread,
Jan 30, 2018, 6:33:01 AM1/30/18
to Tasker

Hello! Can you help me with variables. I made an event profile and now i can recieve the intent. But i dont know how to make the local and then a global variable.. thanks. And sorry for my bad english. :)

Reply all
Reply to author
Forward
0 new messages