gspot/src/components/commands/play.go

25 lines
430 B
Go
Raw Normal View History

2024-02-18 06:57:47 +00:00
package commands
2024-02-18 09:30:19 +00:00
import "github.com/zmb3/spotify/v2"
2024-02-18 06:57:47 +00:00
func (c *Commander) Play() error {
2024-02-18 09:30:19 +00:00
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
2024-02-18 06:57:47 +00:00
}