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.
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.
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:
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.
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.
These actions require no changes, for both, I’m simply using Tasker’s media actions to skip/back the tracks.
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.
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!
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.
Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.