1# Controlling User Playback
2
3Using Spotify Connect, it's possible to control the playback of the currently authenticated user.
4
5## Getting user devices
6
7The `SpotifyWebAPI::getMyDevices()` method can be used to list out a user's devices.
8
9```php
10// Get the Devices
11$api->getMyDevices();
12```
13
14It is worth noting that if all devices have `is_active` set to `false` then using `SpotifyWebApi::play()` will fail.
15
16## Start and stop playback
17```php
18// With Device ID
19$api->play($deviceId, [
20    'uris' => ['TRACK_URI'],
21]);
22
23// Without Device ID
24$api->play(false, [
25    'uris' => ['TRACK_URI'],
26]);
27
28$api->pause();
29```
30
31## Playing the next or previous track
32```php
33$api->previous();
34
35$api->next();
36```
37
38## Adding a track to the queue
39```php
40$api->queue();
41```
42
43## Get the currently playing track
44```php
45$api->getMyCurrentTrack();
46```
47
48## Get info about the current playback
49```php
50$api->getMyCurrentPlaybackInfo();
51```
52
53## Move to a specific position in a track
54```php
55$api->seek([
56    'position_ms' => 60000 + 37000, // Move to the 1.37 minute mark
57]);
58```
59
60## Set repeat and shuffle mode
61```php
62$api->repeat([
63    'state' => 'track',
64]);
65
66$api->shuffle([
67    'state' => false,
68]);
69```
70
71## Control the volume
72```php
73$api->changeVolume([
74    'volume_percent' => 78,
75]);
76```
77
78## Retrying API calls
79Sometimes, a API call might return a `202 Accepted` response code. When this occurs, you should retry the request after a few seconds. For example:
80
81```php
82try {
83    $wasPaused = $api->pause():
84
85    if (!$wasPaused) {
86        $lastResponse = $api->getLastResponse();
87
88        if ($lastResponse['status'] == 202) {
89            // Perform some logic to retry the request after a few seconds
90        }
91    }
92} catch (Exception $e) {
93    $reason = $e->getReason();
94
95    // Check the reason for the failure and handle the error
96}
97```
98
99Read more about working with Spotify Connect in the [Spotify API docs](https://developer.spotify.com/documentation/web-api/guides/using-connect-web-api/).
100