Home Tasker Tasker 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 in style with crypto-currency

New to Tasker?

Tasker Quick Start – Getting started with Tasker

0
From newb to not so newbie in 10 min

Best Tasker Projects

Tasker PC control – #Tutorial 3 (Apps menu)

0
Launch apps and websites from the mobile!

Tasker PC control – #Tutorial 2 (Volume Menu)

0
If you missed the part one, I strongly recommend you to check it out. It tells you all about the framework used, and you...

How to control your PC like a boss – Tasker Project

0
Control PC, and other devices from a custom notification system.

Bluetooth battery monitor – monitor any Bluetooth battery with Tasker

0
Measure the battery use of Bluetooth devices

The Minimal & Elegant giveaway WINNERS

0
Picking the winners live! Livestream and making a Tasker Winners project!

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