A memo on how to control music playback on a smartphone connected to Raspberry pi via Bluetooth with AVRCP
https://gist.github.com/oleq/24e09112b07464acbda1 http://blog.bnikka.com/raspberrypi/raspberrypibluetooth.html Refer to the above URL and turn the Raspberry Pi into a Bluetooth audio (A2DP) receiver so that you can play music from your smartphone. (* It seems that AVRCP cannot be used unless it is connected with A2DP, but maybe there is a way to use it only with AVRCP?)
Demo with dbus-python
BT_MediaPlayer.py
#!/usr/bin/python
import dbus
SERVICE_NAME = "org.bluez"
ADAPTER_INTERFACE = SERVICE_NAME + ".MediaPlayer1"
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object(SERVICE_NAME, "/"),
"org.freedesktop.DBus.ObjectManager")
objects = manager.GetManagedObjects()
if __name__ == '__main__':
for path, ifaces in objects.iteritems():
adapter = ifaces.get(ADAPTER_INTERFACE)
if adapter is None:
continue
print path
player = bus.get_object('org.bluez',path)
BT_Media_iface = dbus.Interface(player, dbus_interface=ADAPTER_INTERFACE)
break
while 1:
s = raw_input()
if s == 'quit':
break
if s == 'play':
BT_Media_iface.Play()
if s == 'pause':
BT_Media_iface.Pause()
if s == 'stop':
BT_Media_iface.Stop()
if s == 'next':
BT_Media_iface.Next()
if s == 'pre':
BT_Media_iface.Previous()
if s == 'show':
track = adapter.get('Track')
print 'Title: ' + track.get('Title')
print 'Artist: ' + track.get('Artist')
print 'Album: ' + track.get('Album')
print 'Genre: ' + track.get('Genre')
print 'NumberOfTracks: ' + str(track.get('NumberOfTracks'))
print 'TrackNumber: ' + str(track.get('TrackNumber'))
print 'Duration: ' + str(track.get('Duration'))
When you execute the above code, it will be in the input waiting state, so enter the command The commands that can be used are as follows
--quit: Program end --show: Display song information --play: Play --pause: Pause --stop: stop --next: Next song --pre: Previous song
Hopefully the path of the connected smartphone will be displayed and you can control the music playback with various commands Below is an example of executing the show command
http://qiita.com/eggman/items/339a9c9b338634ac27a5 https://www.raspberrypi.org/forums/viewtopic.php?t=111486&p=766936