TeamNewPipe / NewPipe

A libre lightweight streaming front-end for Android.
https://newpipe.net
GNU General Public License v3.0
31.38k stars 3.05k forks source link

Volume Button Long Press Playback Control. #6874

Open z3r0r4 opened 3 years ago

z3r0r4 commented 3 years ago

Checklist

Describe the feature you want

I would like NewPipe to have the ability to react to volume button long presses by skipping to the next or previous track. This would require an additional entry in the "Video and Audio" Settings to enable.

Implementation would simply follow along existing tutorials / implementations (https://stackoverflow.com/questions/12950215/onkeydown-and-onkeylongpress) and call the required function to skip to the next or previous track.

The settings entry to enable this feature would need to check the permission android.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER to enable receiving the long press. Failure could show a toast that the permission is missing.

This is in my opinion the only caveat if this feature as there is no neat android implementation for such a permission request. It has to be granted by adb. adb shell pm grant org.schabi.newpipe android.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER However this would not disrupt the usual amateur end user as it is a little known (and thus not expected) Android feature anyways, serving usually only those who know about it.

Alternative is a external app that runs all the time when music is played, for example: https://github.com/Cilenco/skipTrackLongPressVolume, which leads to additional battery drainage and resource usage.

How will everyone benefit from this feature?

In most Android Roms there is currently no other way to use this available feature, which would enrich music listening experience by quite a lot. Especially since NewPipe supports music playing while the screen is off. It would provide a very accessible way to control music playback, while not being able to use the touchscreen of the device (on a car ride/ on a run/ while working).

I intent on looking into implementing this feature myself, although I am unsure on where to best place the onLongPress function (Main? idk) and how to implement the settings entry (this should be solved by looking through other examples in code).

z3r0r4 commented 3 years ago

Alternative is a external app that runs all the time when music is played, for example: https://github.com/Cilenco/skipTrackLongPressVolume, which leads to additional battery drainage and resource usage.

I've tested it thoroughly and its sadly a flawed solution. TL;DR: its unreliable.

As it uses a notification listener to check for running music, it sometimes seems to miss that music is playing and only starts working once the music is restarted. Other times the listener seems to die completely and needs to be dis- and reenabled (this might be due to too aggressive battery optimization by the Os, even though it is (should?) disabled).

z3r0r4 commented 3 years ago

requires the permission

<uses-permission android:name="android.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER" />
z3r0r4 commented 3 years ago

I have implemented this, but imo it is probably not a viable solution to merge into the master. https://github.com/TeamNewPipe/NewPipe/pull/6970#issuecomment-921905399 Working example here: https://github.com/z3r0r4/NewPipe/tree/volume-btn-long-press-skip This can only be compiled using the hidden api, as noted in the comment.