From 9603e4cef0eb22c202f107701ec46e2f052637f3 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 23 Oct 2010 15:53:52 -0400 Subject: [PATCH] Forward / Rewind buttons I have created forward and rewind buttons to draw on the info bar. In addition, I have created seek_sec() to seek the song by X seconds. Right now, the seek buttons add +/- 5 seconds to the current position. --- libsaria/music/__init__.py | 12 ++++++++++++ ocarina/button.py | 14 ++++++++++++++ ocarina/info.py | 2 ++ 3 files changed, 28 insertions(+) diff --git a/libsaria/music/__init__.py b/libsaria/music/__init__.py index 53d6cdad..40318a5d 100644 --- a/libsaria/music/__init__.py +++ b/libsaria/music/__init__.py @@ -60,6 +60,18 @@ def seek(prcnt): return call("SEEK", audio.seek, prcnt) +def seek_sec(sec): + global audio + dur = audio.duration() + if dur > 0: + prcnt = get_progress() + (1 * sec * 1000000000) / audio.duration() + if prcnt > 1: + prcnt = 1 + if prcnt < 0: + prcnt = 0 + seek(prcnt) + + def get_progress(): global audio dur = audio.duration() diff --git a/ocarina/button.py b/ocarina/button.py index e5fe8b8f..a6a14173 100644 --- a/ocarina/button.py +++ b/ocarina/button.py @@ -62,6 +62,20 @@ class NextButton(Button): def clicked(self, button): LS.collection.plist_next() + +class ForwardButton(Button): + def __init__(self): + Button.__init__(self, gtk.STOCK_MEDIA_FORWARD) + def clicked(self, button): + LS.music.seek_sec(5) + + +class RewindButton(Button): + def __init__(self): + Button.__init__(self, gtk.STOCK_MEDIA_REWIND) + def clicked(self, button): + LS.music.seek_sec(-5) + class OpenButton(Button): def __init__(self): Button.__init__(self, gtk.STOCK_OPEN) diff --git a/ocarina/info.py b/ocarina/info.py index a3530c1f..1ae1e45d 100644 --- a/ocarina/info.py +++ b/ocarina/info.py @@ -59,9 +59,11 @@ class InfoBar(Bar): self.pack(self.title, True, True) self.pack(label.TimeLabel()) self.pack(label.LengthLabel2()) + self.pack(button.RewindButton()) self.pack(button.PlayButton()) self.pack(button.PauseButton()) self.pack(button.StopButton()) + self.pack(button.ForwardButton()) self.pack(button.NextButton()) self.pack(button.UpButton(up_button))