I would like my Ubuntu PC sending bluetooth audio commands (play/pause, next/previous song and turn up/down) to other device streaming music over bluetooth to it. In other words, I would like to implement my Ubuntu PC "pretending" to be kind of bluetooth headphones, which are able to change tracks, and pause and resume music.
I have the following setup illustrated with the pavucontrol screenshots below (pt2
is device connected via bluetooth):
In this configuration streaming works as expected (I can hear music streamed from pt2
), but I didn't find any way to be able to send it any signal such as pause/resume playing or change track.
I have already found out that there are many bluetooth protocols allowing specific functions. If I understood specs correctly, what I am interested in is A2DP, which is the way devices are connected now. But under profile dropdown, I have also options HSP/HFP headset head unit, HSP/HFPheadset gateway and off.
I am going to develop my own application in Python which will allow sending such commands, so I am interested in sending them via Python API or via bash commands.
I am asking this question because I am interested in a way how I can communicate with bluetooth devices.
Best Answer
Inspired by @kenn, I decided to go deeper into
dbus
andd-feet
tools. Eventually I reached my goal using the following command:which of course triggered playing music on my mobile device connected to my PC over bluetooth.
Generically for bluetooth devices this command would look like:
In order to check your devices' MAC address run
bt-devices -l
. It will list all known (but not necessarily connected or even discovered) devices with MAC address in parentheses.In order to find allowed commands list, install
d-feet
withsudo apt install d-feet
. After running it, apply search forbluez
query underSystem Bus
tab and find entry with your devices' MAC:There are methods similar to stuff that uses bluetooth headphones under
org.bluez.MediaControl1
. But, when you browse those tree, you can find A WAY more, this is really worth your attention.dbus-send
is a command for sending signals usingdbus
.--system
switch indicates that we want to use stuff fromSystem Bus
d-feet's tab. I haven't try it yet, but I suppose--print-reply
is only for debugging purposes and isn't obligatory.--dest=org.blez
refers toName
in d-feet header./org/bluez/hci0/dev_<mobile_bluetooth_device_mac_address_with_numbers_underscore_separated>
andorg.bluez.MediaControl1.<command>
refer to object tree paths.