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 an option to play audio files in the file menu #129

Merged
merged 7 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 9 additions & 0 deletions src/core/sd_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "sd_functions.h"
#include "mykeyboard.h" // usinf keyboard when calling rename
#include "display.h" // using displayRedStripe as error msg
#include "../modules/others/audio.h"

struct FilePage {
int pageIndex;
Expand Down Expand Up @@ -495,6 +496,14 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) {
if(&fs == &SD) options.push_back({"Copy->LittleFS", [=]() { copyToFs(SD,LittleFS, fileList[index][1]); }});
if(&fs == &LittleFS && sdcardMounted) options.push_back({"Copy->SD", [=]() { copyToFs(LittleFS, SD, fileList[index][1]); }});

#if defined(HAS_NS4168_SPKR)
if(isAudioFile(fileList[index][1])) options.push_back({"Play Audio", [=]() {
playAudioFile(const_cast<fs::FS*>(&fs), fileList[index][1]);
setup_gpio(); //TODO: remove after fix select loop

}});
#endif

options.push_back({"Main Menu", [=]() { backToMenu(); }});
delay(200);
if(!filePicker) loopOptions(options);
Expand Down
1 change: 1 addition & 0 deletions src/core/sd_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <SPI.h>



extern SPIClass sdcardSPI;

bool setupSdCard();
Expand Down
6 changes: 6 additions & 0 deletions src/modules/others/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,10 @@ bool tts(String text){
return true;
}


bool isAudioFile(String filepath) {

return filepath.endsWith(".txt") || filepath.endsWith(".rtttl") ||
filepath.endsWith(".wav") || filepath.endsWith(".mod") || filepath.endsWith(".mp3") ;
}
#endif
4 changes: 3 additions & 1 deletion src/modules/others/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ bool playAudioFile(FS* fs, String filepath); // TODO: bool async arg -> play in

bool playAudioRTTTLString(String song);

bool tts(String text);
bool tts(String text);

bool isAudioFile(String filePath);
Loading