mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-08 21:37:58 -05:00
Add toggle_playback mapping
This commit is contained in:
17
spt/play.go
17
spt/play.go
@@ -33,3 +33,20 @@ func PlayContext(context *spotify.URI) error {
|
||||
PlaybackContext: context,
|
||||
})
|
||||
}
|
||||
|
||||
func TogglePlayback() error {
|
||||
p, err := Client.PlayerCurrentlyPlaying(ctx())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if p.Playing {
|
||||
if err := Client.Pause(ctx()); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := Client.Play(ctx()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user