Ok, so I wanted to write a short guide on how to create a volume slider to control the DFR/DFB hardware volume on Android. Especially for people with the DFR, the default hardware volume level set in Android by default is often too low.
Prerequisites:
Rooted Android Phone
Tasker (on the Play Store)
Termux (on the Play Store)
AlsaMixer (it wasn't on the Play Store for me, but you can download the .apk from other websites)
Summary:
We're going to be creating an icon on the homescreen that when pressed, brings up a slider bar overlay that can be dragged along to adjust the hardware volume. I'm a Tasker noob, so I don't know how to create a widget slider that exists by itself on the homescreen. I'm personally doing this on my Samsung S5 running LineageOS Nougat and the DFR.
Directions:
***Intro and Background***
- plug in the DFR
- open Termux and run these commands:
- you'll get a list of playback devices. It'll be something like:
card 0: ****************
card 1: ****************
card 2: ****************
One of the cards should be labeled DragonFly.if USB OTG detected it properly. In my case, the DragonFly appears as card 1 if I plug in the DFR after Android has already booted. It appears as card 0 if the DFR is connected to the phone already before I've booted into Android.
Say that the DragonFly is card 1 (c1). If you run:
su
alsa_amixer -c1 set PCM 60%
it will set the hardware volume to 60%. So basically we want to have a slider bar that, when changed, runs the following commands for you.
*** Create a Slider Bar ***
- Open Tasker
- Click the "Scenes" tab. A slider is what Tasker calls a "scene," so we're going to create a new scene that includes a slider.
- Click the "+" icon and give the new scene a name. I called mine "Hardware Volume." Press the checkmark.
- Create a box in which you want the volume slider to appear in. This will actually be overlaid on the homescreen in the final product.
- Click the magnifying glass with "X"
- Long press on the screen to add an element or press the "+" icon.
- Select "Slider" on the menu.
- In the "UI" tab, give it a name, like "Hardware Volume," and set the min to 0 and max to 100 and the default to 50.
- In the "Value Selected" tab, click the "+" icon and in "Filter" type "shell" and select "Run Shell."
- Under "Command" type this:
su
alsa_amixer -c0 set PCM %new_val%
alsa_amixer -c1 set PCM %new_val%
Ok, so what's happening here is that every time the slider gets moved, the above commands will run. "%new_val" is the name of a variable that Tasker automatically provides as part of the Slider. It's basically the instantaneous value of whatever the slider is set at, between 0 and 100 in our case. So if you draw the Slider to "56," "%new_val" will be "56," so the command would be "alsa_amixer -c1 set PCM 56%." As previously mentioned, these commands change the hardware volume. And since the DragonFly sometimes appears as card 0 and at other times appears as card 1, at least on my S5, I've set it to run the command for BOTH cards. In my case, if the DragonFly is in, say, card 0, running the command for card 1 doesn't affect anything, and vice versa.
- Checkmark "Use Root"
- Hit the "Action Edit Run Shell" at the upper left to go back.
- Hit the upper left button again.
- Now drag the Slider to where you want it to appear on the screen.
- Once done, hit the upper left button.
Ok, you've finished creating the Slider bar and wiring it up to run the necessary commands when you slide it around. Now you need a way to display it. Oddly enough, Tasker doesn't seem to support simply turning the Slider into a widget and just dragging it onto the homescreen. The only apparent way is to create a button that opens the Slider scene, and to put that *button* on the homescreen.
*** Create a Button to Open the Slider Scene ***
- Open Tasker
- Go to the Tasks tab and hit the "+" icon.
- Create a name for this new task and hit the checkmark. I called mine 'ShowHardwareVolumeSlider'
- Click the "+" icon to add an Action.
- Select "Scene"
- Select "Show Scene"
- Hit the magnifying glass next to "Name" and select your slider scene that you made previously. In my case it's "Hardware Volume."
- "Display As" should be "Activity, Full Window."
- Hit the upper left button "Action Edit"
- At the bottom right hit the square boxes icon. Select the icon you want for this button that will show the slider. I used the built-in white microphone icon.
*** Add the Button to the Homescreen ***
- Before you try and add a Tasker widget, Tasker should be shut down. So open Tasker, go to the upper right, and select "Exit."
- Long press on the home screen.
- Select "Widgets"
- Select "Tasker Task 1 x 1" and drag it to the home screen.
- Select your task for opening the slider scene. In my case it's "ShowHardwareVolumeSlider"
- Press the upper left button to go back to the home screen.
- The widget should now appear. Click on it and the slider bar should appear. Slide it around to easily adjust the hardware volume.