Skip to content

Commit 34ec546

Browse files
committed
Better CannotGetTimeException and CodecException with public constructors (#343)
1 parent 0291caa commit 34ec546

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,22 @@ public int decryptTimeMs() {
121121
}
122122

123123
public static class CannotGetTimeException extends Exception {
124-
CannotGetTimeException() {
124+
public CannotGetTimeException(String message) {
125+
super(message);
126+
}
127+
128+
public CannotGetTimeException(String message, Throwable cause) {
129+
super(message, cause);
125130
}
126131
}
127132

128133
public static class CodecException extends Exception {
129-
CodecException() {
134+
public CodecException(String message) {
135+
super(message);
136+
}
137+
138+
public CodecException(String message, Throwable cause) {
139+
super(message, cause);
130140
}
131141
}
132142
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public int readInternal(@NotNull OutputStream out) throws IOException {
8484

8585
@Override
8686
public int time() throws CannotGetTimeException {
87-
throw new CannotGetTimeException();
87+
throw new CannotGetTimeException("No way to get time on MP3 stream");
8888
}
8989

9090
@Override

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private void readHeader() throws IOException, CodecException {
117117
}
118118

119119
if (joggStreamState.pagein(joggPage) == -1)
120-
throw new CodecException();
120+
throw new CodecException("Failed reading page");
121121

122122
if (joggStreamState.packetout(joggPacket) == -1)
123123
throw new HoleInDataException();
@@ -133,7 +133,7 @@ private void readHeader() throws IOException, CodecException {
133133
buffer = joggSyncState.data;
134134

135135
if (count == 0 && !finished)
136-
throw new CodecException();
136+
throw new CodecException("Buffer under-run");
137137
}
138138
}
139139

@@ -153,7 +153,7 @@ public synchronized int readInternal(@NotNull OutputStream out) throws IOExcepti
153153
// Read more
154154
} else if (result == 1) {
155155
if (joggStreamState.pagein(joggPage) == -1)
156-
throw new CodecException();
156+
throw new CodecException("Failed reading page");
157157

158158
if (joggPage.granulepos() == 0)
159159
return -1;
@@ -244,8 +244,14 @@ public void close() throws IOException {
244244
}
245245

246246
private static class NotVorbisException extends CodecException {
247+
NotVorbisException() {
248+
super("Data read is not vorbis data");
249+
}
247250
}
248251

249252
private static class HoleInDataException extends CodecException {
253+
HoleInDataException() {
254+
super("Hole in vorbis data");
255+
}
250256
}
251257
}

0 commit comments

Comments
 (0)