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:
Bryan Schumaker 2010-10-20 20:04:23 -04:00
parent 507b539295
commit 7b8d2288cd
5 changed files with 41 additions and 5 deletions

View File

@ -19,8 +19,12 @@ music = None
def init():
global vars
global prefs
global music
vars = Map()
prefs = Map("preferences")
import music
event.start("POSTINIT")
@ -32,9 +36,7 @@ def init_pref(key, value):
def startup():
global music
global plugin
import music
import plugin
event.start("PRESTART")

View File

@ -9,6 +9,9 @@ exists = libsaria.path.exists
audio = None
tdelta = None
def ls_init():
libsaria.init_pref("volume", 1.0)
libsaria.event.invite("POSTINIT", ls_init)
def init():
global tdelta
@ -74,3 +77,7 @@ def get_time():
time = time.split(':', 1)[1]
return time
def set_volume(prcnt):
global audio
return call("SETVOLUME", audio.set_volume, prcnt)

View File

@ -16,6 +16,7 @@ def init():
import gst
player = gst.element_factory_make("playbin2", "player")
set_volume(libsaria.prefs["volume"])
time = gst.Format(gst.FORMAT_TIME)
bus = player.get_bus()
bus.add_signal_watch()
@ -103,6 +104,7 @@ def seek(prcnt):
pass
def volume(prcnt):
def set_volume(prcnt):
global player
player.set_property("volume", prcnt)
libsaria.prefs["volume"] = prcnt

View File

@ -1,8 +1,9 @@
# Bryan Schumaker (8/26/2010)
import ocarina
LS = ocarina.libsaria
gtk = ocarina.gtk
LS = ocarina.libsaria
gtk = ocarina.gtk
prefs = LS.prefs
class Button(gtk.Button):
@ -75,3 +76,25 @@ class DownButton(Button):
self.callback = callback
def clicked(self, button):
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()

View File

@ -57,6 +57,7 @@ class InfoBar(Bar):
self.pack(button.PlayButton())
self.pack(button.PauseButton())
self.pack(button.StopButton())
self.pack(button.VolumeButton())
self.pack(button.UpButton(up_button))
libsaria.event.invite("POSTLOAD", self.change_title)
@ -81,6 +82,7 @@ class InfoTab(gtk.Notebook):
hbox.pack_start(button.PlayButton())
hbox.pack_start(button.PauseButton())
hbox.pack_start(button.StopButton())
hbox.pack_start(button.VolumeButton())
hbox.pack_start(button.DownButton(down_button))
self.set_action_widget(hbox, gtk.PACK_END)