test: Add support for using external player

This add support for passing a device player object which is then
registered as a local one in a loopback fashion.
This commit is contained in:
Luiz Augusto von Dentz 2012-10-29 16:41:49 +02:00 committed by Johan Hedberg
parent 5a23a20d16
commit 43f865a8be

View File

@ -9,6 +9,50 @@ import dbus.mainloop.glib
import gobject
class Player(dbus.service.Object):
properties = None
metadata = None
def set_object(self, obj = None):
if obj != None:
bus = dbus.SystemBus()
mp = dbus.Interface(bus.get_object("org.bluez", obj),
"org.bluez.MediaPlayer")
self.properties = mp.GetProperties()
self.metadata = mp.GetTrack()
bus.add_signal_receiver(self.property_changed,
path = obj,
dbus_interface = "org.bluez.MediaPlayer",
signal_name = "PropertyChanged")
bus.add_signal_receiver(self.track_changed,
path = obj,
dbus_interface ="org.bluez.MediaPlayer",
signal_name = "TrackChanged")
else:
self.properties = dbus.Dictionary({
"Equalizer" : "off",
"Repeat" : "off",
"Shuffle" : "off",
"Scan" : "off",
"Status" : "playing",
"Position" : dbus.UInt32(0) },
signature="sv")
self.metadata = dbus.Dictionary({
"Title" : "Title",
"Artist" : "Artist",
"Album" : "Album",
"Genre" : "Genre",
"NumberOfTracks" : dbus.UInt32(10),
"Track" : dbus.UInt32(1),
"Duration" : dbus.UInt32(10000) },
signature="sv")
handler = InputHandler(self)
gobject.io_add_watch(sys.stdin, gobject.IO_IN,
handler.handle)
@dbus.service.method("org.bluez.MediaPlayer",
in_signature="", out_signature="")
def Release(self):
@ -42,6 +86,16 @@ class Player(dbus.service.Object):
def help(self, func):
help(self.__class__.__dict__[func])
def property_changed(self, setting, value):
print("property_changed(%s, %s)" % (setting, value))
self.PropertyChanged(setting, value)
def track_changed(self, metadata):
print("track_changed(%s)" % (metadata))
self.TrackChanged(metadata)
class InputHandler:
commands = { 'TrackChanged': '(metadata)',
'PropertyChanged': '(key, value)',
@ -79,7 +133,6 @@ class InputHandler:
return True
if __name__ == '__main__':
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
@ -99,27 +152,16 @@ if __name__ == '__main__':
player = Player(bus, path)
mainloop = gobject.MainLoop()
properties = dbus.Dictionary({ "Equalizer" : "off",
"Repeat" : "off",
"Shuffle" : "off",
"Scan" : "off",
"Status" : "playing",
"Position" : dbus.UInt32(0) }, signature="sv")
metadata = dbus.Dictionary({ "Title" : "Title",
"Artist" : "Artist",
"Album" : "Album",
"Genre" : "Genre",
"NumberOfTracks" : dbus.UInt32(10),
"Track" : dbus.UInt32(1),
"Duration" : dbus.UInt32(10000) }, signature="sv")
if len(sys.argv) > 2:
player.set_object(sys.argv[2])
else:
player.set_object()
print('Register media player with:\n\tProperties: %s\n\tMetadata: %s' \
% (properties, metadata))
% (player.properties, player.metadata))
handler = InputHandler(player)
gobject.io_add_watch(sys.stdin, gobject.IO_IN, handler.handle)
media.RegisterPlayer(dbus.ObjectPath(path), properties, metadata)
media.RegisterPlayer(dbus.ObjectPath(path), player.properties,
player.metadata)
mainloop.run()