@@ -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 ) {
0 commit comments