2024-02-18 10:46:59 -08:00
|
|
|
package commands
|
|
|
|
|
|
|
|
func (c *Commander) ChangeVolume(amount int) error {
|
2024-02-18 23:33:32 -08:00
|
|
|
state, err := c.Client().PlayerState(c.Context)
|
2024-02-18 10:46:59 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
newVolume := state.Device.Volume + amount
|
|
|
|
if newVolume > 100 {
|
|
|
|
newVolume = 100
|
|
|
|
}
|
|
|
|
if newVolume < 0 {
|
|
|
|
newVolume = 0
|
|
|
|
}
|
2024-02-18 23:33:32 -08:00
|
|
|
return c.Client().Volume(c.Context, newVolume)
|
2024-02-18 10:46:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Commander) Mute() error {
|
|
|
|
return c.ChangeVolume(-100)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Commander) UnMute() error {
|
|
|
|
return c.ChangeVolume(100)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Commander) ToggleMute() error {
|
2024-02-18 23:33:32 -08:00
|
|
|
state, err := c.Client().PlayerState(c.Context)
|
2024-02-18 10:46:59 -08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if state.Device.Volume == 0 {
|
|
|
|
return c.ChangeVolume(100)
|
|
|
|
}
|
|
|
|
return c.ChangeVolume(-100)
|
|
|
|
}
|