Player volume
I can now change the volume using a button in the gui. Additionally, the volume is stored between sessions, and the correct value is loaded when libsaria is initialized.
This commit is contained in:
parent
507b539295
commit
7b8d2288cd
|
@ -19,8 +19,12 @@ music = None
|
||||||
def init():
|
def init():
|
||||||
global vars
|
global vars
|
||||||
global prefs
|
global prefs
|
||||||
|
global music
|
||||||
|
|
||||||
vars = Map()
|
vars = Map()
|
||||||
prefs = Map("preferences")
|
prefs = Map("preferences")
|
||||||
|
import music
|
||||||
|
|
||||||
event.start("POSTINIT")
|
event.start("POSTINIT")
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,9 +36,7 @@ def init_pref(key, value):
|
||||||
|
|
||||||
|
|
||||||
def startup():
|
def startup():
|
||||||
global music
|
|
||||||
global plugin
|
global plugin
|
||||||
import music
|
|
||||||
import plugin
|
import plugin
|
||||||
|
|
||||||
event.start("PRESTART")
|
event.start("PRESTART")
|
||||||
|
|
|
@ -9,6 +9,9 @@ exists = libsaria.path.exists
|
||||||
audio = None
|
audio = None
|
||||||
tdelta = None
|
tdelta = None
|
||||||
|
|
||||||
|
def ls_init():
|
||||||
|
libsaria.init_pref("volume", 1.0)
|
||||||
|
libsaria.event.invite("POSTINIT", ls_init)
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global tdelta
|
global tdelta
|
||||||
|
@ -74,3 +77,7 @@ def get_time():
|
||||||
time = time.split(':', 1)[1]
|
time = time.split(':', 1)[1]
|
||||||
return time
|
return time
|
||||||
|
|
||||||
|
|
||||||
|
def set_volume(prcnt):
|
||||||
|
global audio
|
||||||
|
return call("SETVOLUME", audio.set_volume, prcnt)
|
||||||
|
|
|
@ -16,6 +16,7 @@ def init():
|
||||||
import gst
|
import gst
|
||||||
|
|
||||||
player = gst.element_factory_make("playbin2", "player")
|
player = gst.element_factory_make("playbin2", "player")
|
||||||
|
set_volume(libsaria.prefs["volume"])
|
||||||
time = gst.Format(gst.FORMAT_TIME)
|
time = gst.Format(gst.FORMAT_TIME)
|
||||||
bus = player.get_bus()
|
bus = player.get_bus()
|
||||||
bus.add_signal_watch()
|
bus.add_signal_watch()
|
||||||
|
@ -103,6 +104,7 @@ def seek(prcnt):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def volume(prcnt):
|
def set_volume(prcnt):
|
||||||
global player
|
global player
|
||||||
player.set_property("volume", prcnt)
|
player.set_property("volume", prcnt)
|
||||||
|
libsaria.prefs["volume"] = prcnt
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
# Bryan Schumaker (8/26/2010)
|
# Bryan Schumaker (8/26/2010)
|
||||||
|
|
||||||
import ocarina
|
import ocarina
|
||||||
LS = ocarina.libsaria
|
LS = ocarina.libsaria
|
||||||
gtk = ocarina.gtk
|
gtk = ocarina.gtk
|
||||||
|
prefs = LS.prefs
|
||||||
|
|
||||||
|
|
||||||
class Button(gtk.Button):
|
class Button(gtk.Button):
|
||||||
|
@ -75,3 +76,25 @@ class DownButton(Button):
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
def clicked(self, button):
|
def clicked(self, button):
|
||||||
self.callback()
|
self.callback()
|
||||||
|
|
||||||
|
class VolumeButton(gtk.VolumeButton):
|
||||||
|
def __init__(self):
|
||||||
|
gtk.VolumeButton.__init__(self)
|
||||||
|
self.set_relief(gtk.RELIEF_NONE)
|
||||||
|
|
||||||
|
adj = self.get_adjustment()
|
||||||
|
adj.set_page_increment(0.05)
|
||||||
|
self.set_value(prefs["volume"])
|
||||||
|
self.resize()
|
||||||
|
|
||||||
|
self.connect("value-changed", self.changed)
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
def resize(self):
|
||||||
|
image = self.get_children()[0]
|
||||||
|
icon = image.get_icon_name()[0]
|
||||||
|
image.set_from_icon_name(icon, gtk.ICON_SIZE_MENU)
|
||||||
|
|
||||||
|
def changed(self, widget, value):
|
||||||
|
LS.music.set_volume(value)
|
||||||
|
widget.resize()
|
||||||
|
|
|
@ -57,6 +57,7 @@ class InfoBar(Bar):
|
||||||
self.pack(button.PlayButton())
|
self.pack(button.PlayButton())
|
||||||
self.pack(button.PauseButton())
|
self.pack(button.PauseButton())
|
||||||
self.pack(button.StopButton())
|
self.pack(button.StopButton())
|
||||||
|
self.pack(button.VolumeButton())
|
||||||
self.pack(button.UpButton(up_button))
|
self.pack(button.UpButton(up_button))
|
||||||
|
|
||||||
libsaria.event.invite("POSTLOAD", self.change_title)
|
libsaria.event.invite("POSTLOAD", self.change_title)
|
||||||
|
@ -81,6 +82,7 @@ class InfoTab(gtk.Notebook):
|
||||||
hbox.pack_start(button.PlayButton())
|
hbox.pack_start(button.PlayButton())
|
||||||
hbox.pack_start(button.PauseButton())
|
hbox.pack_start(button.PauseButton())
|
||||||
hbox.pack_start(button.StopButton())
|
hbox.pack_start(button.StopButton())
|
||||||
|
hbox.pack_start(button.VolumeButton())
|
||||||
hbox.pack_start(button.DownButton(down_button))
|
hbox.pack_start(button.DownButton(down_button))
|
||||||
self.set_action_widget(hbox, gtk.PACK_END)
|
self.set_action_widget(hbox, gtk.PACK_END)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue