Skip to content

seekSeconds doesn't work for flac files #42

@HelgeStenstrom

Description

@HelgeStenstrom

I have just tried a little, but it seems that seekSeconds doesn't work if the audio file is a flac file.

public long seekSeconds(int seconds) throws StreamPlayerException {
int durationInSeconds = this.getDurationInSeconds();
//Validate
validateSeconds(seconds, durationInSeconds);
//Calculate Bytes
long totalBytes = getTotalBytes();
double percentage = (seconds * 100) / durationInSeconds;
long bytes = (long) (totalBytes * (percentage / 100));
return seekBytes(this.getEncodedStreamPosition() + bytes);
}

Part of the problem is in TimeTool.durationInMilliseconds_Part2(), where the value on line 110 fall through if the file extension is not mp3, wav or ogg.

private static long durationInMilliseconds_Part2(final File file) {
long milliseconds = -1;
// exists?

This leads to an exception.
UnsupportedOperationException: Trying to skip with seconds {15} > maximum {-1}

If this value is changed to 1000000 (1000 seconds), this exception doesn't happen.
But the seek still doesn't happen.
That's as far as I have investigated.

See also https://github.com/HelgeStenstrom/java-stream-player/tree/appWithFlac

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions