Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pause/resume functionality #18

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Calculate current time (in seconds) for current audio file position
  • Loading branch information
me committed Sep 11, 2019
commit 5f123b90819d810f1b862f33d26340809d62eb8d
16 changes: 16 additions & 0 deletions src/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,22 @@ uint32_t Audio::getAudioFileDuration(){
}
return m_audioFileDuration;
}
//---------------------------------------------------------------------------------------------------------------------
// return curent time in seconds
uint32_t Audio::getAudioCurrentTime(){
uint32_t curTime = 0;
if ( mp3file)
{
uint32_t fileDuration = getAudioFileDuration();
float factor = ( mp3file.position() - m_id3Size ) / ( mp3file.size() - m_id3Size + 1.0f );
if(0.0 < factor)
{
curTime = fileDuration * factor;
}
}
return curTime;
}

//---------------------------------------------------------------------------------------------------------------------
bool Audio::setFilePos(uint32_t pos){
if (!mp3file) return false;
Expand Down
6 changes: 6 additions & 0 deletions src/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class Audio {
* @return uint32_t file duration in seconds, 0 if no file active
*/
uint32_t getAudioFileDuration();
/**
* @brief Get the current plying time in seconds
*
* @return uint32_t current second of audio file, 0 if no file active
*/
uint32_t getAudioCurrentTime();
bool setFilePos(uint32_t pos);
bool setPinout(uint8_t BCLK, uint8_t LRC, uint8_t DOUT);
void stopSong();
Expand Down