summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rhlibrary/player_widget.go53
-rw-r--r--src/rhlibrary/vumeter_widget.go2
2 files changed, 33 insertions, 22 deletions
diff --git a/src/rhlibrary/player_widget.go b/src/rhlibrary/player_widget.go
index f16adfa..261c70d 100644
--- a/src/rhlibrary/player_widget.go
+++ b/src/rhlibrary/player_widget.go
@@ -32,30 +32,44 @@ import (
"github.com/gotk3/gotk3/gtk"
)
-func addPlayButton(box *gtk.Box, p *player.PlayerChan) (err error) {
+var (
+ playIcon *gtk.Image = nil
+ pauseIcon *gtk.Image = nil
+)
+
+func addPlayPauseButton(box *gtk.Box, p *player.PlayerChan) (err error) {
var btn *gtk.Button
- if btn, err = gtk.ButtonNewFromIconName("media-playback-start", gtk.ICON_SIZE_DIALOG); err != nil {
+ if btn, err = gtk.ButtonNew(); err != nil {
return
}
- btn.Connect("clicked", func(_ *gtk.Button) {
- if err := p.Play(); err != nil {
- rhdl.Println(err) // TODO: feedback at GUI?
- }
- })
- box.PackStart(btn, false, false, 0)
- return
-}
-
-func addPauseButton(box *gtk.Box, p *player.PlayerChan) (err error) {
- var btn *gtk.Button
- if btn, err = gtk.ButtonNewFromIconName("media-playback-pause", gtk.ICON_SIZE_DIALOG); err != nil {
+ if playIcon, err = gtk.ImageNewFromIconName("media-playback-start", gtk.ICON_SIZE_DIALOG); err != nil {
return
}
+ if pauseIcon, err = gtk.ImageNewFromIconName("media-playback-pause", gtk.ICON_SIZE_DIALOG); err != nil {
+ return
+ }
+ btn.SetImage(playIcon)
+
btn.Connect("clicked", func(_ *gtk.Button) {
- if err := p.Pause(); err != nil {
+ if err := p.PlayPause(); err != nil {
rhdl.Println(err) // TODO: feedback at GUI?
}
})
+
+ p.AddStateChangeHandler(func(state player.State, _ interface{}) bool {
+ glib.IdleAdd(func() {
+ switch state {
+ case player.IDLE:
+ fallthrough
+ case player.PAUSED:
+ btn.SetImage(playIcon)
+ case player.PLAYING:
+ btn.SetImage(pauseIcon)
+ }
+ })
+ return true
+ }, nil)
+
box.PackStart(btn, false, false, 0)
return
}
@@ -80,10 +94,7 @@ func addButtons(grid *gtk.Grid, p *player.PlayerChan) (err error) {
return
}
- if err = addPlayButton(box, p); err != nil {
- return
- }
- if err = addPauseButton(box, p); err != nil {
+ if err = addPlayPauseButton(box, p); err != nil {
return
}
if err = addStopButton(box, p); err != nil {
@@ -120,7 +131,7 @@ func addScrubber(grid *gtk.Grid, p *player.PlayerChan) (err error) {
}
})
- p.AddUpdateHandler(func(duration time.Duration, pos time.Duration, meter player.Meter, userdata interface{}) bool {
+ p.AddUpdateHandler(func(duration time.Duration, pos time.Duration, _ player.Meter, _ interface{}) bool {
glib.IdleAdd(func() { scale.SetValue(float64(pos) / float64(duration)) })
return true
}, nil)
@@ -135,7 +146,7 @@ func addPlayTime(grid *gtk.Grid, p *player.PlayerChan) (err error) {
return err
}
- p.AddUpdateHandler(func(duration time.Duration, pos time.Duration, meter player.Meter, userdata interface{}) bool {
+ p.AddUpdateHandler(func(_ time.Duration, pos time.Duration, _ player.Meter, _ interface{}) bool {
glib.IdleAdd(func() {
t := time.Unix(0, 0).UTC().Add(pos)
label.SetText(t.Format("15:04:05.0"))
diff --git a/src/rhlibrary/vumeter_widget.go b/src/rhlibrary/vumeter_widget.go
index e83019e..96796d0 100644
--- a/src/rhlibrary/vumeter_widget.go
+++ b/src/rhlibrary/vumeter_widget.go
@@ -190,7 +190,7 @@ func addVUMeterGrid(frame *gtk.Frame, p *player.PlayerChan) (err error) {
return
}
- p.AddUpdateHandler(func(duration time.Duration, pos time.Duration, meter player.Meter, userdata interface{}) bool {
+ p.AddUpdateHandler(func(_ time.Duration, _ time.Duration, meter player.Meter, _ interface{}) bool {
glib.IdleAdd(func() { updateVUMeterLevels(left, right, meter) })
return true
}, nil)