As a quick summary I'm currently building a Raspberry Pi with the ability to act as a Bluetooth A2DP Receiver and routing that audio to a 3.5mm connection. One of the Python scripts I run uses BlueZ and Dbus to communicate with the bluetooth device, At the moment the script I'm using finds a BT device thats been paired with the system before and auto connects to it (Script runs on cron), I can then press Play on my iPhone to start the audio streaming.. However what I am trying to do is once it finds a device and connects to send a dBus command to start the audio playing instead of having to manually press play on the phone itself.
Heres an extract of the code and what I've put in to attempt to make it work but with no luck.
bus = dbus.SystemBus()
#Get bluez dbus objects
man = bus.get_object('org.bluez', '/')
iface = dbus.Interface(man, 'org.bluez.Manager')
adapterPath = iface.DefaultAdapter()
adapter = dbus.Interface(bus.get_object('org.bluez', adapterPath),dbus_interface='org.bluez.Adapter')
devices = adapter.GetProperties()['Devices']
#for each device on this bluetooth adapter look for ones with A2DP sink service UUID and
# register for the propertychanged dbus signal
for d in devices:
dev = dbus.Interface(bus.get_object('org.bluez', d),dbus_interface='org.bluez.Device')
props = dev.GetProperties()
if any(AudioSourceServiceClass_UUID in UUID.upper() for UUID in props["UUIDs"]):
#This device is an A2DP Audio source
devobj = bus.get_object('org.bluez', d)
devobj.Trusted = True
if props["Connected"] == True:
print props["Name"] + " is connected!"
exit()
for d in devices:
dev = dbus.Interface(bus.get_object('org.bluez', d),dbus_interface='org.bluez.Device')
props = dev.GetProperties()
if any(AudioSourceServiceClass_UUID in UUID.upper() for UUID in props["UUIDs"]):
#This device is an A2DP Audio source
print props["Name"] + " has A2DP audio source"
#dev.connect_to_signal("PropertyChanged", handler_for_device(dev))
#dev.connect_to_signal("PropertyChanged", cb)
devobj = bus.get_object('org.bluez', d)
try:
devobj.Connect(dbus_interface='org.bluez.AudioSource')
devobj.Play()
exit()
except dbus.DBusException, e:
print str(e)
In case its not easily seen I added in the line "devobj.Play()" about 4 lines from the bottom.
iPhone has A2DP audio source org.freedesktop.DBus.Error.UnknownMethod: Method "Play" with signature "" on interface "(null)" doesn't exist