Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for bluetooth controls #948

Open
angrykoala opened this issue Dec 17, 2019 · 19 comments
Open

Support for bluetooth controls #948

angrykoala opened this issue Dec 17, 2019 · 19 comments

Comments

@angrykoala
Copy link

Some GUI music players (such as rythmbox) support using Bluetooth headset buttons for play/pause/next (1 click play/pause, 2 clicks for next),

I was wondering if there is a way (or hack) to achieve this with cmus or cmus-remote

@grenzionky
Copy link

grenzionky commented Dec 25, 2019

cmus is recognized a media player by linux, so u just need to call it through a media controller program to get it to do things. so for example
playerctl -p cmus play-pause
will toggle play/pause for cmus.

@angrykoala
Copy link
Author

@grenzionky I'm probably missing something, but trying what you are mentioning only returns No players found

I've seen the project and it looks like it should work as you said (currently running cmus v2.8.0) is there something else I need to make this work?

Thanks

@grenzionky
Copy link

u need to have cmus open when u do that.
try doing playerctl -l to see all available players

@angrykoala
Copy link
Author

Yeah, I though about that, with cmus open playertctl list returns the following:

chrome.instance2289

no cmus listed 😞

@zsugabubus
Copy link

cmus needs MPRIS support enabled in order to being able to communicate with playerctl. Is it enabled for you? Try ./configure CONFIG_MPRIS=y ... (and build from source).

@angrykoala
Copy link
Author

No idea if that's enabled, I'm using cmus installed from ubuntu repository (tbh, I've never build it from source) I'll try as you say though I would like to know if there is a way to enable MPRIS without rebuilding :/

Thanks a lot for your help

@angrykoala
Copy link
Author

Default ./configure seems to work

./configure CONFIG_MPRIS=y

Fails with the following error:

checking for OPUS_LIBS (pkg-config)... no
*** Package opusfile was not found in the pkg-config search path.
*** Perhaps you should add the directory containing `opusfile.pc'
*** to the PKG_CONFIG_PATH environment variable
*** No package 'opusfile' found
checking for LIBSYSTEMD_LIBS (pkg-config)... no
*** Package libsystemd was not found in the pkg-config search path.
*** Perhaps you should add the directory containing `libsystemd.pc'
*** to the PKG_CONFIG_PATH environment variable
*** No package 'libsystemd' found
checking for LIBSYSTEMD_LIBS (pkg-config)... no
*** Package libelogind was not found in the pkg-config search path.
*** Perhaps you should add the directory containing `libelogind.pc'
*** to the PKG_CONFIG_PATH environment variable
*** No package 'libelogind' found
configure failed.

Trying to install libelogind try tries to remove 83 packages with a scary warning message. 😕

@zsugabubus
Copy link

zsugabubus commented Dec 29, 2019

https://www.freedesktop.org/wiki/Specifications/mpris-spec/:

The Media Player Remote Interfacing Specification (MPRIS) is a standard D-Bus interface which aims to provide a common programmatic API for controlling media players.

Default ./configure seems to work

Yeah, it all makes sense if you don't use systemd–it gets disabled by default. (Unfortunatelly,) cmus depends on libsystemd that implements this dbus communication thing.

As far as I can tell you, I fear your only way is to use cmus-remote.

Maybe I'm totally wrong but I guess that your headset sends pause/prev/next keystrokes, so you should bind the appropriate cmus-remote commands to these keys.

@angrykoala
Copy link
Author

@zsugabubus that actually sounds like a reasonable workaround, is there any built-in / recommended way of doing this binding with cmus or just with the default OS binding should be enough?

@zsugabubus
Copy link

zsugabubus commented Dec 29, 2019

The only choice remained is cmus-remote --prev/--next/--pause. I don't know what system you use, but surely there is a way to bind commands to media keys.

@makar47
Copy link

makar47 commented Jan 7, 2020

cmus is recognized a media player by linux, so u just need to call it through a media controller program to get it to do things. so for example
playerctl -p cmus play-pause
will toggle play/pause for cmus.

which program can intercept the keystrokes of a bluetooth device? For example in Ubuntu?

@zsugabubus
Copy link

Search for "ubuntu keybindings". You should be able to create custom bindings in the keyboard settings.

@grenzionky
Copy link

sxhkd should work no matter the desktop environment. its what i use for all my keyboard shortcuts

@angrykoala
Copy link
Author

Although I cannot exactly replicate my ideal behavior, using sxhkd with the following configuration:

XF86AudioPlay
	cmus-remote --next

Althoug I'm not sure how to do it when double-clicking and toggle (pause-play)

@zsugabubus
Copy link

Althoug I'm not sure how to do it when double-clicking and toggle

Which part do you need help exactly? You can use xev (or evtest...) to find out the key names, then you can use cmus-remote --pause to toggle. Or the question is how to distinguish single-clicks from double-clicks (because you receive the same key)?

@angrykoala
Copy link
Author

@zsugabubus The exact behaviour I want is:

  • Single click: Play-pause (the toggling is not a problem)
  • Double click: next

My problem is, first detecting the double click and second having also a single click. Being naive I tried with XF86AudioPlay;XF86AudioPlay to detect double click and It didn't work as expected (I needed 2 clicks, but I had to wait a bit before the second click and following single clicks where also detected). I haven't had a lot of time to tinker around yet

@grenzionky
Copy link

grenzionky commented Jan 9, 2020

you can use xev to detect if double clicking sends a different key than a single click. or check evtest to see the full list of keys ur bluetooth device has, and see if one of them might be what double clicking does. (ie XF86AudioPrev or XF86AudioNext)

@zsugabubus
Copy link

I'm a bit bored, so just in case the headset sends the same keys... try this:

#!/bin/bash
PIDFILE=${TMP:-/tmp}/click.pid
INTERVAL=.3

if [ -f "$PIDFILE" ]; then
  pkill -F "$PIDFILE" -USR1 && exit
fi

echo >"$PIDFILE" $$

clicks=1
trap 'clicks=$((clicks+1)); echo Click!' USR1

while :; do
  sleep $INTERVAL &
  wait && break
done
rm -f "$PIDFILE"

echo Clicks: $clicks
case $clicks in
1) cmus-remote --pause ;;
2) cmus-remote --next ;;
*) cmus-remote ... ;;
esac

@JezerM
Copy link

JezerM commented Apr 6, 2021

I also had this problem with playerctl and this kind of music players, but as it's said in #1043, It's recommendable to install these dependencies to build with ./configure CONFIG_MPRIS=y

sudo apt-get install -qyy \
bash-completion libao-dev libasound2-dev libavcodec-dev \
libavformat-dev libswresample-dev libcddb2-dev libcdio-cdda-dev \
libcue-dev libdiscid-dev libfaad-dev libflac-dev libjack-dev \
libmad0-dev libmodplug-dev libmpcdec-dev libncursesw5-dev \
libopusfile-dev libpulse-dev libroar-dev libsamplerate0-dev \
libsndio-dev libvorbis-dev libwavpack-dev libsystemd-dev pkg-config

Also, there should be a list of dependencies in README, it's not helpful without them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants