-
Notifications
You must be signed in to change notification settings - Fork 11
/
client.go
44 lines (35 loc) · 1.25 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package diskplayer
import (
"github.com/zmb3/spotify"
"golang.org/x/oauth2"
)
// Returns an authenticated Spotify client object, or an error if encountered.
func NewClient(a *spotify.Authenticator, t *oauth2.Token) *SpotifyClient {
c := a.NewClient(t)
return &SpotifyClient{client: &c}
}
type Client interface {
PlayerDevices() ([]spotify.PlayerDevice, error)
Pause() error
TransferPlayback(deviceID spotify.ID, play bool) error
PlayOpt(opt *spotify.PlayOptions) error
}
type SpotifyClient struct {
client *spotify.Client
}
// PlayerDevices will return a list of available Spotify devices. An error is returned if encountered.
func (sc *SpotifyClient) PlayerDevices() ([]spotify.PlayerDevice, error) {
return sc.client.PlayerDevices()
}
// Pause will pause playback for the currently active device.
func (sc *SpotifyClient) Pause() error {
return sc.client.Pause()
}
// TransferPlayback will transfer the Spotify playback to the specified device.
func (sc *SpotifyClient) TransferPlayback(deviceID spotify.ID, play bool) error {
return sc.client.TransferPlayback(deviceID, play)
}
// PlayOpt will initiate playback on the device as specified in the PlayOptions.
func (sc *SpotifyClient) PlayOpt(opt *spotify.PlayOptions) error {
return sc.client.PlayOpt(opt)
}