Skip to content

Commit 0388c4f

Browse files
committed
Allowing GC
1 parent 90deba9 commit 0388c4f

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

core/src/main/java/xyz/gianlu/librespot/player/PlayerRunner.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ void seek(int positionMs) {
310310

311311
void stop() {
312312
stopped = true;
313+
synchronized (pauseLock) {
314+
pauseLock.notifyAll(); // Allow thread to exit
315+
}
313316
}
314317

315318
@Nullable

core/src/main/java/xyz/gianlu/librespot/player/TrackHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ private void load(@NotNull TrackId id, boolean play, int pos) throws IOException
6767
}
6868

6969
private void sendCommand(@NotNull Command command, Object... args) {
70+
if (stopped) throw new IllegalStateException("Looper is stopped!");
7071
commands.add(new CommandBundle(command, args));
7172
}
7273

@@ -119,6 +120,7 @@ PlayerRunner.Controller controller() {
119120
public void close() {
120121
stopped = true;
121122
if (playerRunner != null) playerRunner.stop();
123+
commands.add(new CommandBundle(Command.Terminate));
122124
}
123125

124126
@Nullable
@@ -132,7 +134,7 @@ boolean isTrack(@NotNull TrackId id) {
132134

133135
public enum Command {
134136
Load, Play, Pause,
135-
Stop, Seek
137+
Stop, Seek, Terminate
136138
}
137139

138140
public interface Listener {
@@ -175,6 +177,8 @@ public void run() {
175177
case Seek:
176178
if (playerRunner != null) playerRunner.seek((Integer) cmd.args[0]);
177179
break;
180+
case Terminate:
181+
return;
178182
}
179183
}
180184
} catch (InterruptedException ex) {

0 commit comments

Comments
 (0)