diff --git a/src/contrib/flacdecoder/FlacDecoder.cpp b/src/contrib/flacdecoder/FlacDecoder.cpp index 50575dfcf..119a7c54d 100644 --- a/src/contrib/flacdecoder/FlacDecoder.cpp +++ b/src/contrib/flacdecoder/FlacDecoder.cpp @@ -212,12 +212,20 @@ void FlacDecoder::Destroy() { } double FlacDecoder::SetPosition(double seconds) { - FLAC__uint64 seekToSample = (FLAC__uint64)(this->sampleRate * seconds); + FLAC__uint64 seekToSample = (FLAC__uint64)((double) this->sampleRate * seconds); if (FLAC__stream_decoder_seek_absolute(this->decoder, seekToSample)) { return seconds; } + if (FLAC__stream_decoder_get_state(this->decoder) == FLAC__STREAM_DECODER_SEEK_ERROR) { + if (FLAC__stream_decoder_flush(this->decoder)) { + if (FLAC__stream_decoder_seek_absolute(this->decoder, seekToSample)) { + return seconds; + } + } + } + return -1; }