Skip to content

Commit 0c401cf

Browse files
committed
Removed #time() method and disabled preload for episodes
1 parent b66ef7f commit 0c401cf

4 files changed

Lines changed: 17 additions & 14 deletions

File tree

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ public class PlayerRunner implements Runnable {
3737
LOGGER.trace(String.format("Player ready for playback, codec: %s, fileId: %s", audioFile.codec(), audioFile.describe()));
3838
}
3939

40-
int time() {
41-
return codec.time();
42-
}
43-
4440
@Override
4541
public void run() {
4642
codec.run();

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public final void run() {
7676

7777
protected abstract void readBody() throws IOException, LineUnavailableException, CodecException;
7878

79-
public abstract int time();
79+
public abstract int time() throws CannotGetTimeException;
8080

8181
public void cleanup() {
8282
try {
@@ -104,12 +104,24 @@ public void seek(int positionMs) {
104104
}
105105

106106
protected final void checkPreload() {
107-
if (preloadEnabled && !calledPreload && !stopped && duration - time() <= TRACK_PRELOAD_THRESHOLD) {
107+
int time;
108+
try {
109+
time = time();
110+
} catch (CannotGetTimeException ex) {
111+
return;
112+
}
113+
114+
if (preloadEnabled && !calledPreload && !stopped && duration - time <= TRACK_PRELOAD_THRESHOLD) {
108115
calledPreload = true;
109116
listener.preloadNextTrack();
110117
}
111118
}
112119

120+
public static class CannotGetTimeException extends Exception {
121+
protected CannotGetTimeException() {
122+
}
123+
}
124+
113125
public static class CodecException extends Exception {
114126

115127
CodecException() {

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
public class Mp3Codec extends Codec {
1717
private final LinesHolder.LineWrapper outputLine;
1818
private final byte[] buffer = new byte[BUFFER_SIZE];
19-
private final int size;
2019
private final Sound sound;
21-
private long readSoFar = 0;
2220

2321
public Mp3Codec(@NotNull GeneralAudioStream audioFile, @Nullable NormalizationData normalizationData, Player.@NotNull Configuration conf,
2422
PlayerRunner.@NotNull Listener listener, @NotNull LinesHolder lines, int duration) throws CodecException, IOException, LinesHolder.MixerException {
2523
super(audioFile, normalizationData, conf, listener, lines, duration);
2624

2725
skipMp3Tags(audioIn);
2826
sound = new Sound(audioIn);
29-
size = sound.available();
3027

3128
try {
3229
outputLine = lines.getLineFor(conf, sound.getAudioFormat());
@@ -72,8 +69,6 @@ protected void readBody() throws LineUnavailableException, IOException {
7269
int count = sound.read(buffer);
7370
if (count == -1) break;
7471

75-
readSoFar += count;
76-
7772
line.write(buffer, 0, count);
7873
} else {
7974
line.stop();
@@ -90,8 +85,8 @@ protected void readBody() throws LineUnavailableException, IOException {
9085
}
9186

9287
@Override
93-
public int time() {
94-
return (int) (readSoFar * duration / size); // FIXME: Completely wrong when we'll be able to seek
88+
public int time() throws CannotGetTimeException {
89+
throw new CannotGetTimeException();
9590
}
9691

9792
@Override

core/src/main/java/xyz/gianlu/librespot/player/decrypt/NoopAudioDecrypt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public final class NoopAudioDecrypt implements AudioDecrypt {
77
@Override
88
public void decryptChunk(int chunkIndex, byte[] in, byte[] out) {
99
if (in.length != out.length)
10-
throw new IllegalArgumentException(String.format("Buffers have different lengths! {in: %d, out: %d}", in.length, out.length));
10+
throw new IllegalArgumentException(String.format("Buffers have different lengths! {index: %d, in: %d, out: %d}", chunkIndex, in.length, out.length));
1111

1212
System.arraycopy(in, 0, out, 0, in.length);
1313
}

0 commit comments

Comments
 (0)