Pause will pause the Spotify playback if the Diskplayer is the currently active Spotify device. An error is returned if one is encountered.
(c Client)
| 75 | // Pause will pause the Spotify playback if the Diskplayer is the currently active Spotify device. |
| 76 | // An error is returned if one is encountered. |
| 77 | func Pause(c Client) error { |
| 78 | n := ConfigValue(SPOTIFY_DEVICE_NAME) |
| 79 | ds, err := c.PlayerDevices() |
| 80 | if err != nil { |
| 81 | return err |
| 82 | } |
| 83 | |
| 84 | activeID := activePlayerId(&ds) |
| 85 | if activeID == "" { |
| 86 | return nil |
| 87 | } |
| 88 | |
| 89 | playerID := diskplayerId(&ds, n) |
| 90 | if playerID == "" { |
| 91 | return fmt.Errorf("client identified by %s not found", n) |
| 92 | } |
| 93 | |
| 94 | if activeID == playerID { |
| 95 | err := c.Pause() |
| 96 | if err != nil { |
| 97 | return err |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return nil |
| 102 | } |
| 103 | |
| 104 | // activePlayerIds iterates through the provided player devices and returns the active ID. If there is no active |
| 105 | // Spotify client device the ID will be returned as a nil pointer. |