Skip to content

Commit 4379c5f

Browse files
committed
Merge tag 'v1.5.3'
2 parents a7eceb0 + 62133c0 commit 4379c5f

35 files changed

Lines changed: 418 additions & 249 deletions

CHANGELOG.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,45 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

4-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5-
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
6+
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.5.3] - 28-12-2020
9+
10+
### Added
11+
12+
- Dispatch session closing when using Zeroconf (5b53af7aa5c23a5ed5153e68c5b022aee63ca3e6)
13+
- Allow set volume with relative steps count (#273)
14+
15+
### Changed
16+
17+
- Improved thread usage (#249, #280)
18+
- Catch and log exceptions happening in command/message handling (352d6e3c0cc0a36ea676505e0f761f678f4b11b8,
19+
3229d2cc72ad2c4d364f7c197b0aec38083d577a)
20+
21+
### Fixed
22+
23+
- Fixed parsing some payloads (f6191ff6636dd538b5ebf1090df4eaa9bd062110)
24+
- Fixed double reading of first chunk (e5a8ae712114c344aca43e5ec5f557f7ce9657b9)
25+
- Fixed proxy auth (#274)
26+
- Fixed playback not starting (#277, 26818c619e2fa6f0d4da9f4e96a8e913ccc0468d, abde6b64d68d49e637343560514efc2dca895815,
27+
a79e78a716df74e582504b5d69df455404cef356)
28+
29+
## [1.5.2] - 17-11-2020
30+
31+
### Added
32+
33+
- Added `Player#waitReady()` method (d3149d3843e066986524e14369c5871c22629810)
34+
- Added pass through endpoints for official Spotify API (#255)
35+
- Store and check hash of first chunk of cache data (9ab9f43a91ebbce0e9a3a3c6f3c55a714c756525)
36+
37+
### Fixed
38+
39+
- Fixed `UnsupportedOperationException` when starting playback (#251)
40+
- Close cache files correctly (e953129ed5f0dc4e9931660bd216267557d6010a, #253)
41+
- Fixed starting playback from API (#254)
42+
643

744
## [1.5.2] - 17-11-2020
845
### Added

api/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# API
22
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/xyz.gianlu.librespot/librespot-api/badge.svg)](https://maven-badges.herokuapp.com/maven-central/xyz.gianlu.librespot/librespot-api)
33

4-
This module depends on `librespot-core` and provides an API to interact with the Spotify client.
4+
This module depends on `librespot-player` and, in addition, provides an API to interact with the Spotify client.
55

66
## Available endpoints
77
All the endpoints will respond with `200` if successful or:
@@ -17,7 +17,7 @@ All the endpoints will respond with `200` if successful or:
1717
- `POST /player/next` Skip to next track.
1818
- `POST /player/prev` Skip to previous track.
1919
- `POST /player/seek` Seek to a given position in ms specified by `pos`.
20-
- `POST /player/set-volume` Set volume to a given `volume` value from 0 to 65536.
20+
- `POST /player/set-volume` Either set volume to a given `volume` value (from 0 to 65536), or change it by a `step` count (positive or negative).
2121
- `POST /player/volume-up` Up the volume a little bit.
2222
- `POST /player/volume-down` Lower the volume a little bit.
2323
- `POST /player/current` Retrieve information about the current track (metadata and time).

api/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<parent>
66
<groupId>xyz.gianlu.librespot</groupId>
77
<artifactId>librespot-java</artifactId>
8-
<version>1.5.2</version>
9-
<relativePath>../</relativePath>
8+
<version>1.5.3</version>
9+
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

1212
<artifactId>librespot-api</artifactId>
@@ -59,7 +59,7 @@
5959
<dependency>
6060
<groupId>io.undertow</groupId>
6161
<artifactId>undertow-core</artifactId>
62-
<version>2.1.3.Final</version>
62+
<version>2.2.3.Final</version>
6363
</dependency>
6464
</dependencies>
6565
</project>

api/src/main/java/xyz/gianlu/librespot/api/PlayerWrapper.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@ private PlayerWrapper(@NotNull PlayerConfiguration conf) {
3131
@NotNull
3232
public static PlayerWrapper fromZeroconf(@NotNull ZeroconfServer server, @NotNull PlayerConfiguration conf) {
3333
PlayerWrapper wrapper = new PlayerWrapper(conf);
34-
server.addSessionListener(wrapper::set);
34+
server.addSessionListener(new ZeroconfServer.SessionListener() {
35+
@Override
36+
public void sessionClosing(@NotNull Session session) {
37+
if (wrapper.getSession() == session)
38+
wrapper.clear();
39+
}
40+
41+
@Override
42+
public void sessionChanged(@NotNull Session session) {
43+
wrapper.set(session);
44+
}
45+
});
3546
return wrapper;
3647
}
3748

api/src/main/java/xyz/gianlu/librespot/api/SessionWrapper.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,18 @@ protected SessionWrapper() {
2626
@NotNull
2727
public static SessionWrapper fromZeroconf(@NotNull ZeroconfServer server) {
2828
SessionWrapper wrapper = new SessionWrapper();
29-
server.addSessionListener(wrapper::set);
29+
server.addSessionListener(new ZeroconfServer.SessionListener() {
30+
@Override
31+
public void sessionClosing(@NotNull Session session) {
32+
if (wrapper.getSession() == session)
33+
wrapper.clear();
34+
}
35+
36+
@Override
37+
public void sessionChanged(@NotNull Session session) {
38+
wrapper.set(session);
39+
}
40+
});
3041
return wrapper;
3142
}
3243

api/src/main/java/xyz/gianlu/librespot/api/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static Map<String, Deque<String>> readParameters(@NotNull HttpServerExcha
3030
byte[] buffer = new byte[1024];
3131
int count;
3232
while ((count = in.read(buffer)) > 0) out.write(buffer, 0, count);
33-
body = new String(out.toByteArray());
33+
body = out.toString();
3434
}
3535

3636
return QueryParameterUtils.mergeQueryParametersWithNewQueryString(map, body, "UTF-8");

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

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,42 @@ public PlayerHandler(@NotNull PlayerWrapper wrapper) {
2424
super(wrapper);
2525
}
2626

27-
private static void setVolume(HttpServerExchange exchange, @NotNull Player player, @Nullable String valStr) {
28-
if (valStr == null) {
29-
Utils.invalidParameter(exchange, "volume");
30-
return;
31-
}
27+
private static void setVolume(HttpServerExchange exchange, @NotNull Player player, @Nullable String valStr, @Nullable String stepStr) {
28+
if (valStr != null && stepStr != null) {
29+
// Reject requests with both parameters
30+
Utils.invalidParameter(exchange, "step", "Cannot be passed alongside volume");
31+
} else if (valStr != null) {
32+
// Absolute volume change
33+
int val;
34+
try {
35+
val = Integer.parseInt(valStr);
36+
} catch (Exception ex) {
37+
Utils.invalidParameter(exchange, "volume", "Not an integer");
38+
return;
39+
}
3240

33-
int val;
34-
try {
35-
val = Integer.parseInt(valStr);
36-
} catch (Exception ex) {
37-
Utils.invalidParameter(exchange, "volume", "Not an integer");
38-
return;
39-
}
41+
if (val < 0 || val > Player.VOLUME_MAX) {
42+
Utils.invalidParameter(exchange, "volume", "Must be >= 0 and <= " + Player.VOLUME_MAX);
43+
return;
44+
}
4045

41-
if (val < 0 || val > Player.VOLUME_MAX) {
42-
Utils.invalidParameter(exchange, "volume", "Must be >= 0 and <= " + Player.VOLUME_MAX);
43-
return;
44-
}
46+
player.setVolume(val);
47+
} else if (stepStr != null) {
48+
// Relative volume change in number of steps
49+
int val;
50+
try {
51+
val = Integer.parseInt(stepStr);
52+
} catch (Exception ex) {
53+
Utils.invalidParameter(exchange, "step", "Not an integer");
54+
return;
55+
}
4556

46-
player.setVolume(val);
57+
if (val > 0) player.volumeUp(val);
58+
else if (val < 0) player.volumeDown(Math.abs(val));
59+
else Utils.invalidParameter(exchange, "step", "Must be non zero");
60+
} else {
61+
Utils.invalidParameter(exchange, "volume");
62+
}
4763
}
4864

4965
private static void load(HttpServerExchange exchange, @NotNull Player player, @Nullable String uri, boolean play) {
@@ -168,7 +184,7 @@ protected void handleRequest(@NotNull HttpServerExchange exchange, @NotNull Sess
168184
current(exchange, player);
169185
return;
170186
case SET_VOLUME:
171-
setVolume(exchange, player, Utils.getFirstString(params, "volume"));
187+
setVolume(exchange, player, Utils.getFirstString(params, "volume"), Utils.getFirstString(params, "step"));
172188
return;
173189
case VOLUME_UP:
174190
player.volumeUp();

lib/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Library
22
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/xyz.gianlu.librespot/librespot-lib/badge.svg)](https://maven-badges.herokuapp.com/maven-central/xyz.gianlu.librespot/librespot-lib)
33

4-
54
This module contains all the necessary components to interact with the Spotify infrastructure, but doesn't require configuration files or additional system resources.
65

76
## Getting started

lib/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<parent>
66
<groupId>xyz.gianlu.librespot</groupId>
77
<artifactId>librespot-java</artifactId>
8-
<version>1.5.2</version>
9-
<relativePath>../</relativePath>
8+
<version>1.5.3</version>
9+
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

1212
<artifactId>librespot-lib</artifactId>
@@ -90,7 +90,7 @@
9090
<dependency>
9191
<groupId>com.squareup.okhttp3</groupId>
9292
<artifactId>okhttp</artifactId>
93-
<version>4.8.0</version>
93+
<version>4.9.0</version>
9494
</dependency>
9595

9696
<!-- Commons Net (NTP) -->

lib/src/main/java/xyz/gianlu/librespot/ZeroconfServer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ public void close() throws IOException {
201201
}
202202

203203
public void closeSession() throws IOException {
204+
sessionListeners.forEach(l -> l.sessionClosing(session));
205+
204206
if (session != null) session.close();
205207
session = null;
206208
}
@@ -377,6 +379,18 @@ public void removeSessionListener(@NotNull SessionListener listener) {
377379
}
378380

379381
public interface SessionListener {
382+
/**
383+
* The session instance is going to be closed after this call.
384+
*
385+
* @param session The old {@link Session}
386+
*/
387+
void sessionClosing(@NotNull Session session);
388+
389+
/**
390+
* The session instance changed. {@link #sessionClosing(Session)} has been already called.
391+
*
392+
* @param session The new {@link Session}
393+
*/
380394
void sessionChanged(@NotNull Session session);
381395
}
382396

0 commit comments

Comments
 (0)