Commit f32c40a6 authored by Rafaël Carré's avatar Rafaël Carré

Detect new mpris players, and stick to the last player that ran

Add 3 buttons for loop, repeat and random
Default directory is set to ~ if hardcoded library doesn't exist
parent b63f84d1
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.3.3 on Wed Aug 22 03:00:39 2007 --> <!--Generated with glade3 3.3.4 on Tue Sep 11 23:48:21 2007 -->
<glade-interface> <glade-interface>
<widget class="GtkWindow" id="window1"> <widget class="GtkWindow" id="window1">
<property name="resizable">False</property> <property name="resizable">False</property>
...@@ -135,6 +135,88 @@ ...@@ -135,6 +135,88 @@
</child> </child>
</widget> </widget>
</child> </child>
<child>
<widget class="GtkHBox" id="hbox5">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkToggleButton" id="loop">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="tooltip" translatable="yes">Loop playlist</property>
<property name="response_id">0</property>
<child>
<widget class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="icon_name">media-playlist-repeat</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkToggleButton" id="repeat">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="tooltip" translatable="yes">Repeat current</property>
<property name="response_id">0</property>
<child>
<widget class="GtkHBox" id="hbox6">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">1.</property>
</widget>
</child>
<child>
<widget class="GtkImage" id="image10">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="icon_name">media-playlist-repeat</property>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
</widget>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<widget class="GtkToggleButton" id="shuffle">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="tooltip" translatable="yes">Randomize playlist order</property>
<property name="response_id">0</property>
<child>
<widget class="GtkImage" id="image7">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="icon_name">media-playlist-shuffle</property>
</widget>
</child>
</widget>
<packing>
<property name="position">2</property>
</packing>
</child>
</widget>
<packing>
<property name="position">1</property>
</packing>
</child>
<child> <child>
<widget class="GtkExpander" id="expander2"> <widget class="GtkExpander" id="expander2">
<property name="visible">True</property> <property name="visible">True</property>
...@@ -314,7 +396,7 @@ ...@@ -314,7 +396,7 @@
</child> </child>
</widget> </widget>
<packing> <packing>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</widget> </widget>
......
...@@ -21,11 +21,9 @@ ...@@ -21,11 +21,9 @@
# #
# #
# NOTE: this controller is a SAMPLE, and thus doesn't implement all the D-Bus Media Player specification. http://wiki.videolan.org/index.php/DBus-spec # NOTE: this controller is a SAMPLE, and thus doesn't implement all the
# This is an unfinished document (on the 12/06/2006) and has been designed to be as general as possible. # Media Player Remote Interface Specification (MPRIS for short) available at
# So don't expect that much from this, but basic capabilities should work out of the box (Play/Pause/Next/Add) # http://wiki.xmms2.xmms.se/index.php/Media_Player_Interfaces
#
# Also notice it has been designed first for a previous specificaiton, and thus some code may not work/be disabled
# #
# You'll need pygtk >= 2.10 to use gtk.StatusIcon # You'll need pygtk >= 2.10 to use gtk.StatusIcon
# #
...@@ -41,6 +39,24 @@ global timer ...@@ -41,6 +39,24 @@ global timer
global playing global playing
playing = False playing = False
global shuffle
global repeat
global loop
#mpris doesn't support getting the status of these (at the moment)
shuffle = False
repeat = False
loop = False
global root
global player
global tracklist
global bus
def player_change(newname, a, b):
if b != "" and "org.mpris." in newname:
Connect(newname)
def itemchange_handler(item): def itemchange_handler(item):
gobject.timeout_add( 2000, timeset) gobject.timeout_add( 2000, timeset)
try: try:
...@@ -56,35 +72,26 @@ def itemchange_handler(item): ...@@ -56,35 +72,26 @@ def itemchange_handler(item):
l_artist.set_text(a) l_artist.set_text(a)
l_title.set_text(t) l_title.set_text(t)
#connect to the bus
bus = dbus.SessionBus()
#find the first media player available #find the first media player available
dbus_o = bus.get_object("org.freedesktop.DBus", "/") def Connect(name):
dbus_intf = dbus.Interface(dbus_o, "org.freedesktop.DBus") global root
name_list = dbus_intf.ListNames() global player
name = "" global tracklist
for n in name_list: global bus
if "org.mpris." in n: global playing
name = n
break
if name == "":
print "No MPRIS enabled players on the bus !"
exit()
root_o = bus.get_object(name, "/") root_o = bus.get_object(name, "/")
player_o = bus.get_object(name, "/Player") player_o = bus.get_object(name, "/Player")
tracklist_o = bus.get_object(name, "/TrackList") tracklist_o = bus.get_object(name, "/TrackList")
root = dbus.Interface(root_o, "org.freedesktop.MediaPlayer") root = dbus.Interface(root_o, "org.freedesktop.MediaPlayer")
tracklist = dbus.Interface(tracklist_o, "org.freedesktop.MediaPlayer") tracklist = dbus.Interface(tracklist_o, "org.freedesktop.MediaPlayer")
player = dbus.Interface(player_o, "org.freedesktop.MediaPlayer") player = dbus.Interface(player_o, "org.freedesktop.MediaPlayer")
try:
player_o.connect_to_signal("TrackChange", itemchange_handler, dbus_interface="org.freedesktop.MediaPlayer") player_o.connect_to_signal("TrackChange", itemchange_handler, dbus_interface="org.freedesktop.MediaPlayer")
except: if player.GetStatus() == 0:
True gobject.timeout_add( 2000, timeset)
playing = True
window.set_title(root.Identity())
#plays an element #plays an element
def AddTrack(widget): def AddTrack(widget):
...@@ -122,7 +129,10 @@ def update(widget): ...@@ -122,7 +129,10 @@ def update(widget):
t = item["title"] t = item["title"]
except: t = "" except: t = ""
if t == "": if t == "":
t = item["URI"] try:
t = item["URI"]
except:
t = ""
l_artist.set_text(a) l_artist.set_text(a)
l_title.set_text(t) l_title.set_text(t)
GetPlayStatus(0) GetPlayStatus(0)
...@@ -147,11 +157,26 @@ def Pause(widget): ...@@ -147,11 +157,26 @@ def Pause(widget):
status = player.GetStatus() status = player.GetStatus()
if status == 0: if status == 0:
img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_SMALL_TOOLBAR) img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PAUSE, gtk.ICON_SIZE_SMALL_TOOLBAR)
gobject.timeout_add( 2000, timeset) gobject.timeout_add( 2000, timeset)
else: else:
img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_SMALL_TOOLBAR) img_bt_toggle.set_from_stock(gtk.STOCK_MEDIA_PLAY, gtk.ICON_SIZE_SMALL_TOOLBAR)
update(0) update(0)
def Repeat(widget):
global repeat
repeat = not repeat
player.Repeat(repeat)
def Shuffle(widget):
global shuffle
shuffle = not shuffle
tracklist.Random(shuffle)
def Loop(widget):
global loop
loop = not loop
tracklist.Loop(loop)
#callback for volume #callback for volume
def volchange(widget, data): def volchange(widget, data):
player.VolumeSet(vol.get_value_as_int(), reply_handler=(lambda *args: None), error_handler=(lambda *args: None)) player.VolumeSet(vol.get_value_as_int(), reply_handler=(lambda *args: None), error_handler=(lambda *args: None))
...@@ -197,6 +222,7 @@ def tray_button(widget): ...@@ -197,6 +222,7 @@ def tray_button(widget):
window.move(position[0], position[1]) window.move(position[0], position[1])
window.show() window.show()
#ui setup
xml = gtk.glade.XML('mpris.glade') xml = gtk.glade.XML('mpris.glade')
bt_close = xml.get_widget('close') bt_close = xml.get_widget('close')
...@@ -207,6 +233,9 @@ bt_prev = xml.get_widget('prev') ...@@ -207,6 +233,9 @@ bt_prev = xml.get_widget('prev')
bt_stop = xml.get_widget('stop') bt_stop = xml.get_widget('stop')
bt_toggle = xml.get_widget('toggle') bt_toggle = xml.get_widget('toggle')
bt_mrl = xml.get_widget('AddMRL') bt_mrl = xml.get_widget('AddMRL')
bt_shuffle = xml.get_widget('shuffle')
bt_repeat = xml.get_widget('repeat')
bt_loop = xml.get_widget('loop')
l_artist = xml.get_widget('l_artist') l_artist = xml.get_widget('l_artist')
l_title = xml.get_widget('l_title') l_title = xml.get_widget('l_title')
e_mrl = xml.get_widget('mrl') e_mrl = xml.get_widget('mrl')
...@@ -236,6 +265,9 @@ bt_toggle.connect('clicked', Pause) ...@@ -236,6 +265,9 @@ bt_toggle.connect('clicked', Pause)
bt_next.connect('clicked', Next) bt_next.connect('clicked', Next)
bt_prev.connect('clicked', Prev) bt_prev.connect('clicked', Prev)
bt_stop.connect('clicked', Stop) bt_stop.connect('clicked', Stop)
bt_loop.connect('clicked', Loop)
bt_repeat.connect('clicked', Repeat)
bt_shuffle.connect('clicked', Shuffle)
exp.connect('activate', expander) exp.connect('activate', expander)
vol.connect('change-value', volchange) vol.connect('change-value', volchange)
vol.connect('scroll-event', volchange) vol.connect('scroll-event', volchange)
...@@ -243,18 +275,35 @@ time_s.connect('adjust-bounds', timechange) ...@@ -243,18 +275,35 @@ time_s.connect('adjust-bounds', timechange)
audioicon.set_events(gtk.gdk.BUTTON_PRESS_MASK) audioicon.set_events(gtk.gdk.BUTTON_PRESS_MASK)
audioicon.connect('button_press_event', icon_clicked) audioicon.connect('button_press_event', icon_clicked)
time_s.set_update_policy(gtk.UPDATE_DISCONTINUOUS) time_s.set_update_policy(gtk.UPDATE_DISCONTINUOUS)
gobject.timeout_add( 2000, timeset)
library = "/media/mp3" library = "/media/mp3" #editme
try: try:
os.chdir(library) os.chdir(library)
bt_file.set_current_folder(library) bt_file.set_current_folder(library)
except: except:
print "edit this file to point to your media library" bt_file.set_current_folder(os.path.expanduser("~")
#connect to the bus
bus = dbus.SessionBus()
dbus_names = bus.get_object( "org.freedesktop.DBus", "/org/freedesktop/DBus" )
dbus_names.connect_to_signal("NameOwnerChanged", player_change, dbus_interface="org.freedesktop.DBus")
dbus_o = bus.get_object("org.freedesktop.DBus", "/")
dbus_intf = dbus.Interface(dbus_o, "org.freedesktop.DBus")
name_list = dbus_intf.ListNames()
name = ""
for n in name_list:
if "org.mpris." in n:
name = n
break
if name != "":
Connect(name)
window.set_title(root.Identity())
vol.set_value(player.VolumeGet())
window.set_icon_name('audio-x-generic') window.set_icon_name('audio-x-generic')
window.set_title(root.Identity())
window.show() window.show()
try: try:
...@@ -269,6 +318,5 @@ try: ...@@ -269,6 +318,5 @@ try:
except: except:
True True
position = window.get_position() position = window.get_position()
vol.set_value(player.VolumeGet())
gtk.main() gtk.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment