gspot/src/components/commands/play.go
2024-02-18 01:30:19 -08:00

25 lines
430 B
Go

package commands
import "github.com/zmb3/spotify/v2"
func (c *Commander) Play() error {
err := c.Client.Play(c.Context)
if err != nil {
if isNoActiveError(err) {
deviceID, err := c.activateDevice(c.Context)
if err != nil {
return err
}
err = c.Client.PlayOpt(c.Context, &spotify.PlayOptions{
DeviceID: &deviceID,
})
if err != nil {
return err
}
} else {
return err
}
}
return nil
}