Skip to content

Commit ce45435

Browse files
committed
Fixed #102 + fixed audio deformation due to different line format
1 parent 1cc24bb commit ce45435

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,10 @@ private static class LineWithState {
8181
this.line = line;
8282
}
8383

84-
boolean isCompatible(@NotNull DataLine.Info other) {
85-
for (AudioFormat format : other.getFormats()) {
86-
if (!((DataLine.Info) line.getLineInfo()).isFormatSupported(format))
87-
return false;
88-
}
89-
90-
return true;
84+
boolean isCompatible(@NotNull DataLine.Info otherInfo) {
85+
AudioFormat[] otherFormats = otherInfo.getFormats();
86+
if (otherFormats.length > 1) throw new UnsupportedOperationException();
87+
return line.getFormat().matches(otherFormats[0]);
9188
}
9289

9390
void waitFreed() throws InterruptedException {
@@ -172,5 +169,10 @@ public Control getControl(@NotNull Control.Type type) {
172169
if (openLine == null) throw new IllegalStateException();
173170
return openLine.line.getControl(type);
174171
}
172+
173+
public void drain() {
174+
if (openLine == null) throw new IllegalStateException();
175+
openLine.line.drain();
176+
}
175177
}
176178
}

core/src/main/java/xyz/gianlu/librespot/player/codecs/Mp3Codec.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ protected void readBody() throws LineUnavailableException, IOException, Interrup
8181
}
8282
}
8383
}
84+
85+
outputLine.drain();
8486
}
8587

8688
@Override

core/src/main/java/xyz/gianlu/librespot/player/codecs/VorbisCodec.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ protected void readBody() throws IOException, LineUnavailableException, CodecExc
190190
}
191191
}
192192
}
193+
194+
outputLine.drain();
193195
}
194196

195197
private void decodeCurrentPacket() {

0 commit comments

Comments
 (0)