HomeTaskerStart music with Amazfit devices

Start music with Amazfit devices

Now you can start music playback from Amazfit devices

One of the complaints I made in my Amazfit GTR (review) was that I cannot initiate music playback from the watch itself. I can control it once the playback starts, but there is no option to start music with Amazfit GTR. It’s something that all Huami devices share. I fixed this issue for Xiaomi MiBand 4 (review) before, I will fix it again for probably all Amazfit devices thanks to Tasker.

A different approach

I’m not going to lie, it took me a good while to figure out how to make it work on Amazfit devices. This should work for other Amazfit devices providing you have a compatible phone. My Xiaomi Mi9 (review) works great, but I was not able to use this method on Google Pixel 3 (review). Don’t jump to download section and just apply it, LogCat part may need modifications.

To start music with Amazfit GTR you will need Tasker and AutoNofitication app. If you have never heard about Tasker (Getting started with Tasker), this is an automation tool for Android devices and probably the best app you will ever own, and AutoNotification is a plugin to make it a little bit better.

Start music with Amazfit GTR and others

When I open Music option on my Amazon GTR, the watch checks the playback on the phone, and if media session is present, you will see the track information. Here is the catch, the method works on the ROMs that share this information in the LogCat. If you are unable to see LogCat entries, you will have to try something else.

I was able to pinpoint this action to Audio Manager: getStreamVolume isRestricted mode = 0. It checks if there is a media stream present on your phone. Unfortunately, it is not specifically tied to Amazfit action. Android system uses it in other instances.

I spent a couple of hours testing other Bluetooth related events to find out if there is anything else I could use without much luck.

Plan B

There was no direct action that I could map, but I could use a combination of a Bluetooth event and media stream query to start music with Amazfit GTR.

Each time I’d press the Music option on the watch, Amazfit GTR would connect with my phone and query the media stream. If I can chain these two events – I can have a pretty solid trigger.

Unlikely but possible caveat

Neither of the triggers works on its own. So there could be a situation where these two could create a possible false positive and start the playback. This is possible if you open Amazfit app (before app exclusion kicks in) and in the same half a second time-frame, you will get a notification (Audio Manager query).

Tasker and AutoNotification

I need 2 LogCat triggers (note that your exact entrties can be slightly different):

  • Audio Manager: getStreamVolume isRestricted mode = 0 will start the playback
  • bt_stack [VERBOSE1:gatt_cl.cc(620)] gatt_process_notification arms the playback trigger by setting a 500ms trigger window.

Note that you should use LogCat on your Android phone and press the Music menu on your Amazfit GTR to check if your entries are the same ( feel free to experiment with bt_stack as you will have more than one to pick from.

When the Music menu is open, Tasker uses AM Arm Var profile to set %AMAmazfitTest variable to 1, then changes it back to 0. This is a trigger window in which if media stream had been queried, it will start the music with playback control action.

TASKER PROFILE: AM Arm Var
Profile: AM Arm Var
    Restore: no
    Event: Logcat Entry [ Output Variables:* Component:bt_stack 
        Filter:[VERBOSE1:gatt_cl.cc(620)] gatt_process_notification 
        Grep Filter (Check Help):Off ]
Enter: AM Amaz Var 
    A1: Variable Set [ Name:%AMAmazfitTest To:1 
        Recurse Variables:Off Do Maths:Off 
        Append:Off Max Rounding Digits:3 ] 
    A2: Wait [ MS:500 Seconds:0 Minutes:0 Hours:0 Days:0 ] 
    A3: Variable Set [ Name:%AMAmazfitTest To:0 
        Recurse Variables:Off Do Maths:Off 
        Append:Off Max Rounding Digits:3 ] 
TASKER PROFILE: AM Play Music
Profile: AM Play Music
    Restore: no
    Event: Logcat Entry [ Output Variables:* Component:AudioManager
    Filter:getStreamVolume isRestricted mode = 0 
    Grep Filter (Check Help):Off ]
    Application: Not Amazfit
Enter: AM Start Playback 
    Abort Existing Task
    
    A1: Media Control [ Cmd:Play [Simulated Only] 
        Simulate Media Button:On Package/App 
        Name:Play Music Use Notification If Available:Off ] 
        If [ %AMAmazfitTest ~ 1 ]
    
    
    <2nd method>
    A2: Anchor 
    
    A3: [X] Variable Set [ Name:%playlist To:xxxx
    A4: [X] Send Intent [ Action:android.media.action.MEDIA_PLAY_FROM_SEARCH
        Cat:Default Mime Type: 
        Data: Extra:android.intent.extra.focus:vnd.android.cursor.item/playlist 
        Extra:query:%playlist Extra: Package:
        Class: Target:Activity ] 
        If [ %AMAmazfitTest ~ 1 ]
         
    Recurse Variables:Off Do Maths:Off Append:Off Max Rounding Digits:3 ]

Playback Action vs Intent

There are 2 ways to start music with Amazfit. You can simply use Media Control action in Tasker to simulate play action, or supply an intent and start a playlist of your choice.

If you can’t get Tasker to start the music playback, make sure that Google Play Music (or your selected player) isn’t kill by Android processes. On my Xiaomi Mi9, I had to enable Auto-start and remove battery optimizations for the music app.

Media Control

This method will continue music playback from the last session. Select Play action – and use simulate a button to start music playback on your Android phone. This should only trigger IF %AMAmazfitTest is set to 1.

Intent

Before you start, note this won’t work with autogenerated playlists on Google Play Music – so if you want to start “Thumbs up” – you would need to make a copy of that list and name it in a different way.

I can use Android Intent action to send the query to Google Play Music to look for a specific playlist. For the ease of use, I will specify the playlist in a variable so you could change this at will.

Action: android.media.action.MEDIA_PLAY_FROM_SEARCH
Cat: Default
<no Mime Type>
<no Data>
Extra: android.intent.extra.focus:vnd.android.cursor.item/playlist
Extra: query:%playlist
<No package>
<No class>
Target: Activity 

The intent will open the music app and start playing the selected playlist. To wrap things nicely, add 2 second wait time and “Go Home” action to return to the default screen.

Disable Profile when streaming

To prevent further accidental false positives, I used AutoNotification to monitor the Media Playback. Once media stream is in progress, Tasker deactivates the triggering profile AM Play Music.

TASKER PROFILE: AM Play Music Notification
Profile: AM Play Music Notification 
    Restore: no
    State: AutoNotification Intercept 
    [ Configuration:Has Media Session: true
    Notification App: Google Play Music
    Package Name: com.google.android.music ]
Enter: AM Profile Control - 
    A1: Profile Status [ Name:AM Play Music Set:Off ] 

Exit: AM Profile Control + 
    A1: Profile Status [ Name:AM Play Music Set:On ] 

To clean up triggers further, you will note that I have excluded Amazfit app from the bt_stack trigger. This app will extensively trigger the bt_stack event.

Conclusion, comments and download

If you try this, leave me a comment in this Reddit thread. Let me know what Amazfit device did you use and share your LogCat triggers. This way other users will have an easier time implementing this. The only thing that is missing, is the ability to actually store the music on the Amazfit GTR – perhaps in the next iteration?

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

New to Tasker?

Tasker Quick Start – Getting started with Tasker

0
From newb to not so newbie in 10 min

Best Tasker Projects

How to use Raspberry PI as WOL (wake on lan) server

0
While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

How to wake on LAN computers and put it to sleep with Power Menu,...

0
How to Wake on LAN properly via Android, Alexa, Google Assistant and Web

7 awesome Bluetooth keyboard shortcuts for Android

0
7 unique Android shortcuts that you can add to any Bluetooth keyboard.

Smart overnight charging with Tasker

0
Still keeping your phone plugged in overnight? Try smarter overnight charging with this profile

One thing that Join app can’t do and how to fix it with Tasker

0
It's not possible to share the clipboard automatically between join accounts registered to 2 different emails. But you can fix this with tasker.

Essential Guides

Tasker: Seconds into DD:HH:MM:SS (dynamic)

0
It's time to.... ok it's a pun, but I will show you how to master time and convert seconds to DD:HH:MM:SS dynamically

4 ways to organise Tasker projects

0
Keep your Tasker tidy!

A better way to store Tasker credentials

0
The more clever way of managing credentials

Annoyed with dozens of AutoApps populating your app drawer? Here is a fix!

0
Clear your app drawer from the clutter in seconds

Putting AutoTools pie chart to a good use – SSID logger

0
Who wants a piece of the pie (chart)?