1

Is it possible to read the state of the "play" button inside a music app's notification and use it as an event to activate/deactivate a Tasker profiles?

I need to run certain commands when playback starts or stops in a music app. I think Tasker can use notifications from specific apps as events for activating its profiles, or even look for specific text in the notifications. But can it respond to the media buttons in the music player's notification, or in the music app itself? I cannot use the %atmusicplaying variable from Autotools plugin or similar approaches to check if music is playing, because I use the device to stream the music over DLNA and for some reason the device doesn't return the music state as "playing" in this case (see another question and its answer's comments).

  • I don't have a DLNA server or I would have tried this first before suggesting, but you can try looking into logcat or adb shell dumpsys activity to find out if an intent is sent when the play/pause media button is pressed in the notification for your app. If yes, you can configure Tasker to intercept that intent and run a task. Alternatively, AutoInput might be configured to detect taps for the notification and run a task. See if any of this works. – Firelord Dec 3 '18 at 9:04
  • 1
    Thanks, will try the command and see if I can figure out what might be related to pressing play/pause. Hope to find a more accurate way to intercept the play/pause action than taps on the notification, because the button might be pushed inside the app, or the notification might be tapped only to bring the app to foreground without changing the playing state. Also, I am not playing music from a DLNA server, I am streaming to a DLNA device (a streamer, which receives the signal over DLNA and outputs analog sound), if that changes anything. – mnd Dec 3 '18 at 11:08
  • Well, this is not too easy.. Because in the output of adb shell dumpsys activity there are no timestamps, so I can't just search by the time I pressed the play/pause button. But I found some repeating patterns, like this one: #47: BroadcastRecord{303c389 u0 com.n7mobile.upnpplayer.RECEIVE_POSITION_CHANGE}act=com.n7mobile.upnpplayer.RECEIVE_POSITION_CHANGE flg=0x10 (has extras) – mnd Dec 3 '18 at 18:57
  • You can refer to this documentation to know how best to use logcat. For the timestamp, do adb logcat -v long,descriptive. – Firelord Dec 3 '18 at 19:01
  • 1
    I think I see what Tasker should capture. The logcat returns the states of streaming, e.g. n7.UpnpAVTransport: state PLAYING, 12-03 18:55:08.207 +0000 9692 9692 D n7.UpnpAVTransport: state STOPPED' or n7.ServiceUpnp#api: current state: -1, n7.ServiceUpnp#api: current state: 1`. Reading these values should do the job to enable/disable profiles. Now just have to figure out how to monitor and read them with Tasker, if it's possible. – mnd Dec 3 '18 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.