Unverified Commit ed773f15 authored by Wolle's avatar Wolle Committed by GitHub

resume local file after stopSong()

uint32_t stopSong(); //returns the real fileposition at current time
bool connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos = 0); // jumps to resumeFilePos after reading fileheader
parent bdace928
......@@ -597,13 +597,15 @@ void Audio::UTF8toASCII(char* str){
str[j] = 0;
}
//---------------------------------------------------------------------------------------------------------------------
bool Audio::connecttoSD(const char* path) {
return connecttoFS(SD, path);
bool Audio::connecttoSD(const char* path, uint32_t resumeFilePos) {
return connecttoFS(SD, path, resumeFilePos);
}
//---------------------------------------------------------------------------------------------------------------------
bool Audio::connecttoFS(fs::FS &fs, const char* path) {
bool Audio::connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos) {
if(strlen(path)>255) return false;
m_resumeFilePos = resumeFilePos;
char audioName[256];
setDefaults(); // free buffers an set defaults
memcpy(audioName, path, strlen(path)+1);
......@@ -2046,13 +2048,18 @@ int Audio::read_OGG_Header(uint8_t *data, size_t len){
return 0;
}
//---------------------------------------------------------------------------------------------------------------------
void Audio::stopSong() {
uint32_t Audio::stopSong() {
uint32_t pos = 0;
if(m_f_running) {
m_f_running = false;
audiofile.close();
if(m_f_localfile){
pos = getFilePos() - inBufferFilled();
audiofile.close();
}
}
memset(m_outBuff, 0, sizeof(m_outBuff)); //Clear OutputBuffer
i2s_zero_dma_buffer((i2s_port_t) m_i2s_num);
return pos;
}
//---------------------------------------------------------------------------------------------------------------------
void Audio::playI2Sremains() { // returns true if all dma_buffs flushed
......@@ -2785,6 +2792,15 @@ void Audio::processLocalFile() {
f_stream = false;
return;
}
if(!f_stream && m_controlCounter == 100) {
f_stream = true;
if(audio_info) audio_info("stream ready");
if(m_resumeFilePos){
setFilePos(m_resumeFilePos);
log_i("m_resumeFilePos %i", m_resumeFilePos);
}
}
bytesCanBeWritten = InBuff.writeSpace();
//----------------------------------------------------------------------------------------------------
// some files contain further data after the audio block (e.g. pictures).
......@@ -2802,17 +2818,11 @@ void Audio::processLocalFile() {
InBuff.bytesWritten(bytesAddedToBuffer);
}
// if(psramFound() && bytesAddedToBuffer >4096)
// vTaskDelay(2);// PSRAM has a bottleneck in the queue, so wait a little bit
if(bytesAddedToBuffer == -1) bytesAddedToBuffer = 0; // read error? eof?
bytesCanBeRead = InBuff.bufferFilled();
if(bytesCanBeRead > InBuff.getMaxBlockSize()) bytesCanBeRead = InBuff.getMaxBlockSize();
if(bytesCanBeRead == InBuff.getMaxBlockSize()) { // mp3 or aac frame complete?
if(!f_stream) {
f_stream = true;
if(audio_info) audio_info("stream ready");
}
if(m_controlCounter != 100){
if(m_codec == CODEC_WAV){
int res = read_WAV_Header(InBuff.getReadPtr(), bytesCanBeRead);
......@@ -2865,6 +2875,7 @@ void Audio::processLocalFile() {
}
return;
}
if(!bytesAddedToBuffer) { // eof
bytesCanBeRead = InBuff.bufferFilled();
if(bytesCanBeRead > 200){
......
......@@ -2,7 +2,7 @@
* Audio.h
*
* Created on: Oct 26,2018
* Updated on: Feb 04,2022
* Updated on: Feb 19,2022
* Author: Wolle (schreibfaul1)
*/
......@@ -159,8 +159,8 @@ public:
void setBufsize(int rambuf_sz, int psrambuf_sz);
bool connecttohost(const char* host, const char* user = "", const char* pwd = "");
bool connecttospeech(const char* speech, const char* lang);
bool connecttoFS(fs::FS &fs, const char* path);
bool connecttoSD(const char* path);
bool connecttoFS(fs::FS &fs, const char* path, uint32_t resumeFilePos = 0);
bool connecttoSD(const char* path, uint32_t resumeFilePos = 0);
bool setFileLoop(bool input);//TEST loop
bool setAudioPlayPosition(uint16_t sec);
bool setFilePos(uint32_t pos);
......@@ -170,7 +170,7 @@ public:
bool pauseResume();
bool isRunning() {return m_f_running;}
void loop();
void stopSong();
uint32_t stopSong();
void forceMono(bool m);
void setBalance(int8_t bal = 0);
void setVolume(uint8_t vol);
......@@ -446,6 +446,7 @@ private:
uint32_t m_contentlength = 0; // Stores the length if the stream comes from fileserver
uint32_t m_bytesNotDecoded = 0; // pictures or something else that comes with the stream
uint32_t m_PlayingStartTime = 0; // Stores the milliseconds after the start of the audio
uint32_t m_resumeFilePos = 0; // the return value from stopSong() can be entered here
bool m_f_swm = true; // Stream without metadata
bool m_f_unsync = false; // set within ID3 tag but not used
bool m_f_exthdr = false; // ID3 extended header
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment