HomeTaskerTasker Smart NavBar #6 Music controller

Tasker Smart NavBar #6 Music controller

Add Music Playback controls to Android NavBar

I can’t believe I needed someone to actually suggest this in the comments (thank you M.Muthuk Kunalan). The Android NavBar is a perfectly adequate place to put the music controls in. NavBar Music Controller is a standalone project which is part of the Smart NavBar series which introduce 6 different actions you can perform from the Android navigation bar.

NavBar Music Controller

The premise is simple, during the music playback, I want to have the basic music controls (skip, play/pause, forward). I used Google Play Music in this example, but with a bit of luck* this could be adapted to any other music player as well.

*The tricky part was actually to sync the music playback state, so the NavBar Music Controller would display the correct icon even if the playback status had been changed via Bluetooth remote or the notification itself. For this to work the media Android notification has display 2 properties:

  • active playback notification has to be persistent (not dismissable)
  • paused music notification needs to be dismissable (non-persistent)

If these conditions are satisfied, you will be able to display the NavBar Music Controller with dynamic icons.

Creating the NavBar Music Controller

The music actions appear when media notification is displayed in the notification bar. I can detect the event using AutoNotification. Sadly, I couldn’t use the icon information, or assigned actions, as the variables with thse values were not useful (scrabled data or the same path for each icon). To resolve the play/pause issue I have to rely on the fact that “paused” notification is dismissable and I can detect that with AutoNotification.

I created 2 profiles – one to display the set of controls with a music playback paused and one with the play button instead. Depending on which media notificaiton is present, I will display one or the other.

TASKER PROFILE: NB Create Music Play
Profile: NB Create Music Play 
	Event: AutoNotification Intercept [ 
	Configuration:Event Behaviour: true
				  Notification Type: Only Created Notifications
				  Persistency Type: Persistent Only
				  Has Media Session: true
				  Notification App: Google Play Music
                  Get All Fields : false ]
Enter: NB Music Play 
	
	A1: Navigation Bar [ Left:back[1.0] 
						 Center:home[1.0] 
						 Right:task(NB Music back)[1.0],task(NB Music pause=:=NB Kill)[1.0],task(NB Music skip)[1.0] ]  

TASKER PROFILE: NB Create Music Pause
Profile: NB Create Music Pause 
	Event: AutoNotification Intercept [ 
			Configuration:Event Behaviour: true
			Notification Type: Only Created Notifications
			Persistency Type: Non-Persistent Only
			Has Media Session: true
			Notification App: Google Play Music
			Get All Fields : false ]
Enter: NB Music Pause 
	
	A1: Navigation Bar [ Left:back[1.0] 
							 Center:home[1.0] 
							 Right:task(NB Music back)[1.0],task(NB Music play=:=NB Kill)[1.0],task(NB Music skip)[1.0] ]   

The NavBar Music Controller is dismissed when the notification for media playback is dismissed too. I have selected a bunch of dismissing methods available in the AutoNotification plugin to support different scenarios.

TASKER PROFILE: NB Cancel Music
Profile: NB Cancel Music 
	Event: AutoNotification Intercept [ 
			Configuration:Event Behaviour: true
			Notification Type: Only Cancelled Notifications
			Cancel Reason: Original app cancelled,
						   Original app cancelled all,
						   User cancelled,
						   User cancelled all,
						   Notification click,
						   App was killed
			Persistency Type: Both
			Notification App: Google Play Music ]
Enter: NB Music Reset 
	A1: Navigation Bar [ Left:back[1.0] 
						 Center:home[1.0] 
						 Right: ]  

Music tasks

With the framework sorted, all I had to do is to control the playback itself, and build the tasks which will contain the appropriate icons and actions. Tasker comes with set of media actions, so the tasks are very simple:

Play

Using Tasker’s media actions I am starting the playback of the music followed by the Flash action to give me a visual feedback. I don’t have to update the NavBar as the new Google Play Music notification will be issued, and the Tasker Profile will update itself.

TASKER TASK: NB Music play
NB Music play 
	A1: Flash [ Text:Play Long:Off ] 
	A2: Media Control [ Cmd:Play [Simulated Only] Simulate Media Button:On App:Play Music ] 

Pause

In the similar manner to “play” I’m using the flash action for the feeback and the built-in media actions in Tasker to pause the playback. Since the Android media notification will toggle the persistency, the new NavBar will be issues automatically.

TASKER TASK: NB Music pause
NB Music play 
	A1: Flash [ Text:Pause Long:Off ] 
	A2: Media Control [ Cmd:Pause [Simulated Only] Simulate Media Button:On App:Play Music ] 

Skip/Forward

These actions require no changes, for both, I’m simply using Tasker’s media actions to skip/back the tracks.

TASKER TASK: NB skip/back
NB Music skip 
	A1: Media Control [ Cmd:Next Simulate Media Button:On App:Play Music ] 
	A2: Flash [ Text:Skip Long:Off ]

NB Music back
	A1: Media Control [ Cmd:Previous Simulate Media Button:On App:Play Music ] 
	A2: Flash [ Text:Back Long:Off ] 

Double Tap to kill app

It was only fair to add an option to kill music playback and turn off the NavBar Music Controller. I liked the action to the double tap on play/pause so when used, it will kill the Google Play Music app. Once the notification isn’t present the NavBar Music Controller goes away too.

TASKER TASK: NB kill
NB Kill 
	A1: Kill App [ App: Play Music Use Root:On ] 

Smart NavBar integration

This is a stand-alone version of the Smart NavBar actions. Once I created the standalone versions for each NavBar Task I will show you how to integrate it together. You can read the tutorial about this now!

Conclusion

The NavBar Music Controller is a great addition to the NavBar and will work great with other mods too once the Smarter NavBar project has been released. You can use it in the standalone mode until then. If you have any questions or suggestions you can always share it in this Reddit thread.

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)?