Skip to content

Commit 996f22b

Browse files
committed
add SpotifyListenerAdapter, improve async api, version 1.0.2
1 parent 067e84a commit 996f22b

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repositories {
1414
}
1515
1616
dependencies {
17-
implementation 'com.github.LabyStudio:java-spotify-api:1.0.1:all'
17+
implementation 'com.github.LabyStudio:java-spotify-api:1.0.2:all'
1818
}
1919
```
2020

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'de.labystudio'
7-
version '1.0.1'
7+
version '1.0.2'
88

99
compileJava {
1010
sourceCompatibility = '1.8'

src/main/java/de/labystudio/spotifyapi/SpotifyAPI.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import de.labystudio.spotifyapi.model.Track;
44

5+
import java.util.concurrent.CompletableFuture;
6+
57
/**
68
* This is the main interface for the SpotifyAPI.
79
* It is used to get the current track and the current position of a song.
@@ -13,11 +15,21 @@ public interface SpotifyAPI {
1315

1416
/**
1517
* Initialize the SpotifyAPI and connect to the Spotify process.
18+
* Initializing the api will block the current thread until the connection is established.
1619
*
1720
* @return the initialized SpotifyAPI
1821
*/
1922
SpotifyAPI initialize();
2023

24+
/**
25+
* Initialize the SpotifyAPI and connect to the Spotify process asynchronously.
26+
*
27+
* @return a future that will contain the initialized SpotifyAPI
28+
*/
29+
default CompletableFuture<SpotifyAPI> initializeAsync() {
30+
return CompletableFuture.supplyAsync(this::initialize);
31+
}
32+
2133
/**
2234
* Returns the current track that is playing right now
2335
* It can be null if the api haven't received any playback changes yet.

src/main/java/de/labystudio/spotifyapi/SpotifyAPIFactory.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,33 @@ public static SpotifyAPI create() {
2626
String os = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
2727

2828
if (os.contains("win")) {
29-
return new WinSpotifyAPI().initialize();
29+
return new WinSpotifyAPI();
3030
}
3131
if (os.contains("mac")) {
32-
return new OSXSpotifyApi().initialize();
32+
return new OSXSpotifyApi();
3333
}
3434

3535
throw new IllegalStateException("Unsupported OS: " + os);
3636
}
3737

38+
/**
39+
* Create an initialized SpotifyAPI instance.
40+
* Initializing will block the current thread until the SpotifyAPI instance is ready.
41+
*
42+
* @return A new SpotifyAPI instance.
43+
*/
44+
public static SpotifyAPI createInitialized() {
45+
return create().initialize();
46+
}
47+
3848
/**
3949
* Creates a new SpotifyAPI instance for the current platform asynchronously.
4050
* Currently, only Windows and OSX are supported.
4151
*
4252
* @return A future that will contain the SpotifyAPI instance.
4353
*/
44-
public static CompletableFuture<SpotifyAPI> createAsync() {
45-
return CompletableFuture.supplyAsync(SpotifyAPIFactory::create);
54+
public static CompletableFuture<SpotifyAPI> createInitializedAsync() {
55+
return CompletableFuture.supplyAsync(SpotifyAPIFactory::createInitialized);
4656
}
4757

4858
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package de.labystudio.spotifyapi;
2+
3+
import de.labystudio.spotifyapi.model.Track;
4+
5+
public class SpotifyListenerAdapter implements SpotifyListener {
6+
7+
@Override
8+
public void onConnect() {
9+
10+
}
11+
12+
@Override
13+
public void onTrackChanged(Track track) {
14+
15+
}
16+
17+
@Override
18+
public void onPositionChanged(int position) {
19+
20+
}
21+
22+
@Override
23+
public void onPlayBackChanged(boolean isPlaying) {
24+
25+
}
26+
27+
@Override
28+
public void onSync() {
29+
30+
}
31+
32+
@Override
33+
public void onDisconnect(Exception exception) {
34+
35+
}
36+
}

0 commit comments

Comments
 (0)