add persistent volume

This commit is contained in:
raziman 2020-07-12 09:48:48 +08:00
parent b7b3b7c7a9
commit 77c8c7615b
2 changed files with 10 additions and 0 deletions

View File

@ -188,11 +188,17 @@ func (p *Player) Play() {
// volume up and volume down using -0.5 or +0.5
func (p *Player) Volume(v float64) float64 {
// check if no songs playing currently
if p._volume == nil {
p.volume += v
return p.volume
}
defer func() {
volume := int(p.volume*10) + 50
viper.Set("volume", volume)
}()
speaker.Lock()
p._volume.Volume += v
p.volume = p._volume.Volume

View File

@ -182,6 +182,10 @@ func start(application *tview.Application) {
appLog(err)
}
if err := viper.WriteConfig(); err != nil {
appLog(err)
}
application.Stop()
})