Skip to content

Commit 100d248

Browse files
committed
Added shuffle parameter to /player/load endpoint (#330)
1 parent 7747677 commit 100d248

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

api/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ All the endpoints will respond with `200` if successful or:
1010
- `503` If the session is reconnecting (`Retry-After` is always 10 seconds)
1111

1212
### Player
13-
- `POST /player/load` Load a track from a given URI. The request body should contain two parameters: `uri` and `play`.
13+
- `POST /player/load` Load a track from a given URI `uri`, can specify to start playing with `play` and to shuffle with `shuffle`.
1414
- `POST /player/play-pause` Toggle play/pause status. Useful when using a remote.
1515
- `POST /player/pause` Pause playback.
1616
- `POST /player/resume` Resume playback.
@@ -69,7 +69,7 @@ Use any endpoint from the [public Web API](https://developer.spotify.com/documen
6969
The method, body, and content type headers will pass through. Additionally, you can specify an `X-Spotify-Scope` header to override the requested scope, by default all will be requested.
7070

7171
## Examples
72-
`curl -X POST -d "uri=spotify:track:xxxxxxxxxxxxxxxxxxxxxx&play=true" http://localhost:24879/player/load`
72+
`curl -X POST -d "uri=spotify:track:xxxxxxxxxxxxxxxxxxxxxx&play=true&shuffle=true" http://localhost:24879/player/load`
7373

7474
`curl -X POST http://localhost:24879/metadata/track/spotify:track:xxxxxxxxxxxxxxxxxxxxxx`
7575

api/src/main/java/xyz/gianlu/librespot/api/handlers/PlayerHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,13 @@ private static void setRepeat(HttpServerExchange exchange, @NotNull Player playe
8484
}
8585
}
8686

87-
private static void load(HttpServerExchange exchange, @NotNull Player player, @Nullable String uri, boolean play) {
87+
private static void load(HttpServerExchange exchange, @NotNull Player player, @Nullable String uri, boolean play, boolean shuffle) {
8888
if (uri == null) {
8989
Utils.invalidParameter(exchange, "uri");
9090
return;
9191
}
9292

93+
player.setShuffle(shuffle);
9394
player.load(uri, play);
9495
}
9596

@@ -210,7 +211,7 @@ protected void handleRequest(@NotNull HttpServerExchange exchange, @NotNull Sess
210211
player.volumeDown();
211212
return;
212213
case LOAD:
213-
load(exchange, player, Utils.getFirstString(params, "uri"), Utils.getFirstBoolean(params, "play"));
214+
load(exchange, player, Utils.getFirstString(params, "uri"), Utils.getFirstBoolean(params, "play"), Utils.getFirstBoolean(params, "shuffle"));
214215
return;
215216
case PLAY_PAUSE:
216217
player.playPause();

0 commit comments

Comments
 (0)