Skip to content

Commit 5607c5d

Browse files
committed
Added onStartedLoading and onFinishedLoading listeners
1 parent b3d61f4 commit 5607c5d

4 files changed

Lines changed: 66 additions & 3 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ public void onPanicState(@NotNull Player player) {
139139
dispatch(obj);
140140
}
141141

142+
@Override
143+
public void onStartedLoading(@NotNull Player player) {
144+
}
145+
146+
@Override
147+
public void onFinishedLoading(@NotNull Player player) {
148+
}
149+
142150
@Override
143151
public void onSessionCleared(@NotNull Session old) {
144152
old.removeReconnectionListener(this);

player/src/main/java/xyz/gianlu/librespot/player/Player.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ public void startedLoading() {
363363
state.setBuffering(true);
364364
state.updated();
365365
}
366+
367+
events.startedLoading();
366368
}
367369

368370
@Override
@@ -371,6 +373,7 @@ public void finishedLoading(@NotNull MetadataWrapper metadata) {
371373
state.setBuffering(false);
372374
state.updated();
373375

376+
events.finishedLoading();
374377
events.metadataAvailable();
375378
}
376379

@@ -878,6 +881,10 @@ public interface EventsListener {
878881
void onVolumeChanged(@NotNull Player player, @Range(from = 0, to = 1) float volume);
879882

880883
void onPanicState(@NotNull Player player);
884+
885+
void onStartedLoading(@NotNull Player player);
886+
887+
void onFinishedLoading(@NotNull Player player);
881888
}
882889

883890
/**
@@ -1038,6 +1045,14 @@ public void onVolumeChanged(@NotNull Player player, @Range(from = 0, to = 1) flo
10381045
@Override
10391046
public void onPanicState(@NotNull Player player) {
10401047
}
1048+
1049+
@Override
1050+
public void onStartedLoading(@NotNull Player player) {
1051+
}
1052+
1053+
@Override
1054+
public void onFinishedLoading(@NotNull Player player) {
1055+
}
10411056
});
10421057
}
10431058
}
@@ -1067,6 +1082,16 @@ void contextChanged() {
10671082
executorService.execute(() -> l.onContextChanged(Player.this, uri));
10681083
}
10691084

1085+
void startedLoading() {
1086+
for (EventsListener l : new ArrayList<>(listeners))
1087+
executorService.execute(() -> l.onStartedLoading(Player.this));
1088+
}
1089+
1090+
void finishedLoading() {
1091+
for (EventsListener l : new ArrayList<>(listeners))
1092+
executorService.execute(() -> l.onFinishedLoading(Player.this));
1093+
}
1094+
10701095
void trackChanged(boolean userInitiated) {
10711096
PlayableId id = state.getCurrentPlayable();
10721097
if (id == null) return;

player/src/main/java/xyz/gianlu/librespot/player/ShellEvents.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ public void onPanicState(@NotNull Player player) {
119119
exec(conf.onPanicState);
120120
}
121121

122+
@Override
123+
public void onStartedLoading(@NotNull Player player) {
124+
exec(conf.onStartedLoading);
125+
}
126+
127+
@Override
128+
public void onFinishedLoading(@NotNull Player player) {
129+
exec(conf.onFinishedLoading);
130+
}
131+
122132
@Override
123133
public void onConnectionDropped() {
124134
exec(conf.onConnectionDropped);
@@ -144,10 +154,13 @@ public static class Configuration {
144154
public final String onPanicState;
145155
public final String onConnectionDropped;
146156
public final String onConnectionEstablished;
157+
public final String onStartedLoading;
158+
public final String onFinishedLoading;
147159

148160
public Configuration(boolean enabled, boolean executeWithBash, String onContextChanged, String onTrackChanged, String onPlaybackEnded, String onPlaybackPaused,
149161
String onPlaybackResumed, String onTrackSeeked, String onMetadataAvailable, String onVolumeChanged,
150-
String onInactiveSession, String onPanicState, String onConnectionDropped, String onConnectionEstablished) {
162+
String onInactiveSession, String onPanicState, String onConnectionDropped, String onConnectionEstablished,
163+
String onStartedLoading, String onFinishedLoading) {
151164
this.enabled = enabled;
152165
this.executeWithBash = executeWithBash;
153166
this.onContextChanged = onContextChanged;
@@ -162,6 +175,8 @@ public Configuration(boolean enabled, boolean executeWithBash, String onContextC
162175
this.onPanicState = onPanicState;
163176
this.onConnectionDropped = onConnectionDropped;
164177
this.onConnectionEstablished = onConnectionEstablished;
178+
this.onStartedLoading = onStartedLoading;
179+
this.onFinishedLoading = onFinishedLoading;
165180
}
166181

167182
public static class Builder {
@@ -179,6 +194,8 @@ public static class Builder {
179194
private String onPanicState = "";
180195
private String onConnectionDropped = "";
181196
private String onConnectionEstablished = "";
197+
private String onStartedLoading = "";
198+
private String onFinishedLoading = "";
182199

183200
public Builder() {
184201
}
@@ -253,10 +270,21 @@ public Builder setOnConnectionEstablished(String command) {
253270
return this;
254271
}
255272

273+
public Builder setOnStartedLoading(String onStartedLoading) {
274+
this.onStartedLoading = onStartedLoading;
275+
return this;
276+
}
277+
278+
public Builder setOnFinishedLoading(String onFinishedLoading) {
279+
this.onFinishedLoading = onFinishedLoading;
280+
return this;
281+
}
282+
256283
@NotNull
257284
public Configuration build() {
258285
return new Configuration(enabled, executeWithBash, onContextChanged, onTrackChanged, onPlaybackEnded, onPlaybackPaused, onPlaybackResumed,
259-
onTrackSeeked, onMetadataAvailable, onVolumeChanged, onInactiveSession, onPanicState, onConnectionDropped, onConnectionEstablished);
286+
onTrackSeeked, onMetadataAvailable, onVolumeChanged, onInactiveSession, onPanicState, onConnectionDropped, onConnectionEstablished,
287+
onStartedLoading, onFinishedLoading);
260288
}
261289
}
262290
}

player/src/main/resources/default.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@ onVolumeChanged = ""
7979
onInactiveSession = ""
8080
onPanicState = ""
8181
onConnectionDropped = ""
82-
onConnectionEstablished = ""
82+
onConnectionEstablished = ""
83+
onStartedLoading = ""
84+
onFinishedLoading = ""

0 commit comments

Comments
 (0)