Skip to content

Commit d1158ae

Browse files
committed
fix exception handling for mac, version 1.1.11
1 parent 0e3e902 commit d1158ae

File tree

4 files changed

+46
-45
lines changed

4 files changed

+46
-45
lines changed

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.1.10'
7+
version '1.1.11'
88

99
compileJava {
1010
sourceCompatibility = '1.8'

src/main/java/de/labystudio/spotifyapi/platform/AbstractTickSpotifyAPI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public SpotifyAPI initialize(SpotifyConfiguration configuration) {
5555
return this;
5656
}
5757

58-
private void onInternalTick() {
58+
protected void onInternalTick() {
5959
try {
6060
// Check if we passed the exception timeout
6161
long timeSinceLastException = System.currentTimeMillis() - this.timeLastException;
@@ -78,7 +78,7 @@ private void onInternalTick() {
7878
}
7979
}
8080

81-
protected abstract void onTick();
81+
protected abstract void onTick() throws Exception;
8282

8383
@Override
8484
public void registerListener(SpotifyListener listener) {

src/main/java/de/labystudio/spotifyapi/platform/osx/OSXSpotifyApi.java

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -27,57 +27,58 @@ public class OSXSpotifyApi extends AbstractTickSpotifyAPI {
2727
private long lastTimePositionUpdated;
2828

2929
@Override
30-
protected void onTick() {
31-
try {
32-
String trackId = this.appleScript.getTrackId();
30+
protected void onTick() throws Exception {
31+
String trackId = this.appleScript.getTrackId();
3332

34-
// Handle on connect
35-
if (!this.connected && !trackId.isEmpty()) {
36-
this.connected = true;
37-
this.listeners.forEach(SpotifyListener::onConnect);
38-
}
33+
// Handle on connect
34+
if (!this.connected && !trackId.isEmpty()) {
35+
this.connected = true;
36+
this.listeners.forEach(SpotifyListener::onConnect);
37+
}
3938

40-
// Handle track changes
41-
if (!Objects.equals(trackId, this.currentTrack == null ? null : this.currentTrack.getId())) {
42-
String trackName = this.appleScript.getTrackName();
43-
String trackArtist = this.appleScript.getTrackArtist();
44-
int trackLength = this.appleScript.getTrackLength();
39+
// Handle track changes
40+
if (!Objects.equals(trackId, this.currentTrack == null ? null : this.currentTrack.getId())) {
41+
String trackName = this.appleScript.getTrackName();
42+
String trackArtist = this.appleScript.getTrackArtist();
43+
int trackLength = this.appleScript.getTrackLength();
4544

46-
boolean isFirstTrack = !this.hasTrack();
45+
boolean isFirstTrack = !this.hasTrack();
4746

48-
Track track = new Track(trackId, trackName, trackArtist, trackLength);
49-
this.currentTrack = track;
47+
Track track = new Track(trackId, trackName, trackArtist, trackLength);
48+
this.currentTrack = track;
5049

51-
// Fire on track changed
52-
this.listeners.forEach(listener -> listener.onTrackChanged(track));
50+
// Fire on track changed
51+
this.listeners.forEach(listener -> listener.onTrackChanged(track));
5352

54-
// Reset position on song change
55-
if (!isFirstTrack) {
56-
this.updatePosition(0);
57-
}
53+
// Reset position on song change
54+
if (!isFirstTrack) {
55+
this.updatePosition(0);
5856
}
57+
}
5958

60-
// Handle is playing changes
61-
boolean isPlaying = this.appleScript.getPlayerState();
62-
if (isPlaying != this.isPlaying) {
63-
this.isPlaying = isPlaying;
64-
65-
// Fire on play back changed
66-
this.listeners.forEach(listener -> listener.onPlayBackChanged(isPlaying));
67-
}
59+
// Handle is playing changes
60+
boolean isPlaying = this.appleScript.getPlayerState();
61+
if (isPlaying != this.isPlaying) {
62+
this.isPlaying = isPlaying;
6863

69-
// Handle position changes
70-
int position = this.appleScript.getPlayerPosition();
71-
if (!this.hasPosition() || Math.abs(position - this.getPosition()) > 1000) {
72-
this.updatePosition(position);
73-
}
64+
// Fire on play back changed
65+
this.listeners.forEach(listener -> listener.onPlayBackChanged(isPlaying));
66+
}
7467

75-
// Fire keep alive
76-
this.listeners.forEach(SpotifyListener::onSync);
77-
} catch (Exception e) {
78-
this.listeners.forEach(listener -> listener.onDisconnect(e));
79-
this.connected = false;
68+
// Handle position changes
69+
int position = this.appleScript.getPlayerPosition();
70+
if (!this.hasPosition() || Math.abs(position - this.getPosition()) > 1000) {
71+
this.updatePosition(position);
8072
}
73+
74+
// Fire keep alive
75+
this.listeners.forEach(SpotifyListener::onSync);
76+
}
77+
78+
@Override
79+
public void stop() {
80+
super.stop();
81+
this.connected = false;
8182
}
8283

8384
private void updatePosition(int position) {

src/main/java/de/labystudio/spotifyapi/platform/windows/WinSpotifyAPI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class WinSpotifyAPI extends AbstractTickSpotifyAPI {
3636
* Updates the current track, position and playback state.
3737
* If the process is not connected, it will try to connect to the Spotify process.
3838
*/
39-
protected void onTick() {
39+
protected void onTick() throws Exception {
4040
if (!this.isConnected()) {
4141
// Connect
4242
this.process = new SpotifyProcess();
@@ -173,7 +173,7 @@ public void pressMediaKey(MediaKey mediaKey) {
173173
}
174174

175175
// Update state immediately
176-
this.onTick();
176+
this.onInternalTick();
177177
}
178178

179179
@Override

0 commit comments

Comments
 (0)