Skip to content

Commit 2c3d9ce

Browse files
committed
Cleanup of MixingLine + fix stuttering when skipping next
1 parent 661c171 commit 2c3d9ce

2 files changed

Lines changed: 12 additions & 27 deletions

File tree

core/src/main/java/xyz/gianlu/librespot/player/mixing/MixingLine.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ public final void write(int b) {
103103
public abstract void clear();
104104

105105
public abstract void emptyBuffer();
106-
107-
@NotNull
108-
public abstract MixingOutput stream();
109106
}
110107

111108
public class FirstOutputStream extends MixingOutput {
@@ -119,21 +116,21 @@ public void write(@NotNull byte[] b, int off, int len) {
119116
@Override
120117
public void toggle(boolean enabled) {
121118
if (enabled == fe) return;
122-
if (enabled && (fout == null || fout != this)) throw new IllegalStateException();
119+
if (enabled && (fout == null || fout != this)) return;
123120
fe = enabled;
124121
LOGGER.trace("Toggle first channel: " + enabled);
125122
}
126123

127124
@Override
128125
public void gain(float gain) {
129-
if (fout == null || fout != this) throw new IllegalStateException();
126+
if (fout == null || fout != this) return;
130127
fg = gain;
131128
}
132129

133130
@Override
134131
@SuppressWarnings("DuplicatedCode")
135132
public void clear() {
136-
if (fout == null || fout != this) throw new IllegalStateException();
133+
if (fout == null || fout != this) return;
137134

138135
fg = 1;
139136
fe = false;
@@ -145,15 +142,9 @@ public void clear() {
145142
}
146143
}
147144

148-
@Override
149-
public @NotNull MixingOutput stream() {
150-
if (fout == null || fout != this) throw new IllegalStateException();
151-
return this;
152-
}
153-
154145
@Override
155146
public void emptyBuffer() {
156-
if (fout == null || fout != this) throw new IllegalStateException();
147+
if (fout == null || fout != this) return;
157148
fcb.empty();
158149
}
159150
}
@@ -169,21 +160,21 @@ public void write(@NotNull byte[] b, int off, int len) {
169160
@Override
170161
public void toggle(boolean enabled) {
171162
if (enabled == se) return;
172-
if (enabled && (sout == null || sout != this)) throw new IllegalStateException();
163+
if (enabled && (sout == null || sout != this)) return;
173164
se = enabled;
174165
LOGGER.trace("Toggle second channel: " + enabled);
175166
}
176167

177168
@Override
178169
public void gain(float gain) {
179-
if (sout == null || sout != this) throw new IllegalStateException();
170+
if (sout == null || sout != this) return;
180171
sg = gain;
181172
}
182173

183174
@Override
184175
@SuppressWarnings("DuplicatedCode")
185176
public void clear() {
186-
if (sout == null || sout != this) throw new IllegalStateException();
177+
if (sout == null || sout != this) return;
187178

188179
sg = 1;
189180
se = false;
@@ -195,15 +186,9 @@ public void clear() {
195186
}
196187
}
197188

198-
@Override
199-
public @NotNull MixingOutput stream() {
200-
if (sout == null || sout != this) throw new IllegalStateException();
201-
return this;
202-
}
203-
204189
@Override
205190
public void emptyBuffer() {
206-
if (sout == null || sout != this) throw new IllegalStateException();
191+
if (sout == null || sout != this) return;
207192
scb.empty();
208193
}
209194
}

core/src/main/java/xyz/gianlu/librespot/player/playback/PlayerQueueEntry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ int getTimeNoThrow() {
172172
*/
173173
void seek(int pos) {
174174
seekTime = pos;
175-
if (output != null) output.stream().emptyBuffer();
175+
if (output != null) output.emptyBuffer();
176176
}
177177

178178
/**
@@ -190,8 +190,6 @@ void setOutput(@NotNull MixingLine.MixingOutput output) {
190190
this.output = output;
191191
playbackLock.notifyAll();
192192
}
193-
194-
this.output.toggle(true);
195193
}
196194

197195
/**
@@ -270,6 +268,7 @@ public void run() {
270268
}
271269

272270
if (closed) break;
271+
output.toggle(true);
273272

274273
if (seekTime != -1) {
275274
codec.seek(seekTime);
@@ -290,7 +289,7 @@ public void run() {
290289
}
291290

292291
try {
293-
if (codec.writeSomeTo(output.stream()) == -1) {
292+
if (codec.writeSomeTo(output) == -1) {
294293
try {
295294
int time = codec.time();
296295
LOGGER.debug("Player time offset is {}. {id: {}}", metadata.duration() - time, playbackId);
@@ -311,6 +310,7 @@ public void run() {
311310
}
312311
}
313312

313+
output.toggle(false);
314314
listener.playbackEnded(this);
315315
LOGGER.trace("{} terminated.", this);
316316
}

0 commit comments

Comments
 (0)