8

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): enter image description here enter image description here

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.

  • I do not have occasion to test out, but I'm interested in the solution too because I get the same problem, in a discussion here: ubuntuforums.org/… seemse need just to add input module to load, but information are not a lot in the post. – AtomiX84 Jan 30 at 12:16
  • @AtomiX84 I have an impression that I have rather opposite issue. I want my PC pretending headphones, not headphones connected to my PC steering music played on it. – pt12lol Jan 30 at 12:24
  • 1
  • @kenn I would like to see quite specific thing, while answer you are linking to looks rather generically. Could you provide more detailed example specific to my use case? – pt12lol Jan 30 at 15:08
  • I am not an expert in that area, you can search for github. Also take a look at this link stackoverflow.com/questions/48932249/… – kenn Jan 30 at 15:21
7

Inspired by @kenn, I decided to go deeper into dbus and d-feet tools. Eventually I reached my goal using the following command:

dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_44_78_3E_85_9D_6F org.bluez.MediaControl1.Play

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:

dbus-send --system --print-reply --dest=org.bluez /org/bluez/hci0/dev_<mobile_bluetooth_device_mac_address_with_numbers_underscore_separated> org.bluez.MediaControl1.<command_to_send>

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 with sudo apt install d-feet. After running it, apply search for bluez query under System Bus tab and find entry with your devices' MAC:

enter image description here

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 using dbus. --system switch indicates that we want to use stuff from System 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 to Name in d-feet header. /org/bluez/hci0/dev_<mobile_bluetooth_device_mac_address_with_numbers_underscore_separated> and org.bluez.MediaControl1.<command> refer to object tree paths.

  • This is great ! Did you map those dbus-send commands to the media-buttons of your PC or how do you intent to use it ? – Robert Riedl Feb 1 at 12:54
  • 1
    @Robert Riedl I wanted to catch my gamepad buttons down events and map them with specific commands sent to mobile device which streams music to my computer. Motivation for this project was my son who loves to be a music manager, but I not wanted him spending too much time by the screen. So I decided to provide him other kind of UX ;) – pt12lol Feb 1 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.