From 29316ffd134143ee976f4c1b3dbb5c9c7482d579 Mon Sep 17 00:00:00 2001 From: Stefan Ostermann Date: Mon, 7 Jul 2025 21:28:37 +0200 Subject: [PATCH] fixed jump to second of playtime --- lib/ESP32-audioI2S/src/Audio.cpp | 35 ++++++++------------------------ 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/lib/ESP32-audioI2S/src/Audio.cpp b/lib/ESP32-audioI2S/src/Audio.cpp index 57c6303..b48efba 100644 --- a/lib/ESP32-audioI2S/src/Audio.cpp +++ b/lib/ESP32-audioI2S/src/Audio.cpp @@ -4694,18 +4694,9 @@ uint32_t Audio::getAudioCurrentTime() { // return current time in seconds } //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ bool Audio::setAudioPlayPosition(uint16_t sec) { - if(!m_f_psramFound) { log_w("PSRAM must be activated"); return false;} // guard - if(m_dataMode != AUDIO_LOCALFILE /* && m_streamType == ST_WEBFILE */) return false; // guard - if(!m_avr_bitrate) return false; // guard - //if(m_codec == CODEC_OPUS) return false; // not impl. yet - //if(m_codec == CODEC_VORBIS) return false; // not impl. yet - // Jump to an absolute position in time within an audio file - // e.g. setAudioPlayPosition(300) sets the pointer at pos 5 min if(sec > getAudioFileDuration()) sec = getAudioFileDuration(); uint32_t filepos = m_audioDataStart + (m_avr_bitrate * sec / 8); - if(m_dataMode == AUDIO_LOCALFILE) return setFilePos(filepos); -// if(m_streamType == ST_WEBFILE) return httpRange(m_lastHost, filepos); - return false; + return setFilePos(filepos); } //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ void Audio::setVolumeSteps(uint8_t steps) { @@ -4737,23 +4728,15 @@ bool Audio::setTimeOffset(int sec) { // fast forward or rewind the current posit } //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ bool Audio::setFilePos(uint32_t pos) { - if(!m_f_psramFound) { log_w("PSRAM must be activated"); return false;} // guard - if(m_dataMode != AUDIO_LOCALFILE /* && m_streamType == ST_WEBFILE */) return false; // guard - if(m_dataMode == AUDIO_LOCALFILE && !audiofile) return false; // guard - if(m_codec == CODEC_AAC) return false; // guard, not impl. yet - - uint32_t startAB = m_audioDataStart; // audioblock begin - uint32_t endAB = m_audioDataStart + m_audioDataSize; // audioblock end - if(pos < (int32_t)startAB) {pos = startAB;} - if(pos >= (int32_t)endAB) {pos = endAB;} - - + if(m_codec == CODEC_OPUS) return false; // not impl. yet + if(m_codec == CODEC_VORBIS) return false; // not impl. yet + if(!audiofile) return false; + if(pos < m_audioDataStart) pos = m_audioDataStart; // issue #96 + if(pos > m_fileSize) pos = m_fileSize; + m_resumeFilePos = pos; + memset(m_outBuff, 0, 2048 * 2 * sizeof(int16_t)); m_validSamples = 0; - if(m_dataMode == AUDIO_LOCALFILE /* || m_streamType == ST_WEBFILE */) { - m_resumeFilePos = pos; // used in processLocalFile() - return true; - } - return false; + return true; } //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ bool Audio::setSampleRate(uint32_t sampRate) {