Directly start a song from list
This commit is contained in:
parent
0697ad90be
commit
183c17c37c
|
|
@ -66,6 +66,7 @@ const char index_html[] PROGMEM = R"rawliteral(
|
|||
var liText = this.innerText;
|
||||
var inputField = document.getElementById('titleid');
|
||||
inputField.value = liText;
|
||||
playNamedSong(liText);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -92,6 +93,16 @@ const char index_html[] PROGMEM = R"rawliteral(
|
|||
document.getElementById("state").innerHTML = state;
|
||||
}
|
||||
|
||||
function playNamedSong(song) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/playnamed");
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
//application/x-www-form-urlencoded
|
||||
var body = song;
|
||||
xhr.send("title="+encodeURIComponent(body));
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>)rawliteral";
|
||||
|
|
@ -5,6 +5,8 @@ void stop();
|
|||
|
||||
void start();
|
||||
|
||||
bool playFile(const char* filename, uint32_t resumeFilePos = 0);
|
||||
|
||||
void loop2(void* parameter);
|
||||
|
||||
void named_song_action(AsyncWebServerRequest *request);
|
||||
|
|
@ -30,6 +32,22 @@ String getRFIDString(byte uidByte[10])
|
|||
return uidString;
|
||||
}
|
||||
|
||||
void writeFile(fs::FS &fs, const char * path, const char * message){
|
||||
Serial.printf("Writing file: %s\n", path);
|
||||
|
||||
File file = fs.open(path, FILE_WRITE);
|
||||
if(!file){
|
||||
Serial.println("Failed to open file for writing");
|
||||
return;
|
||||
}
|
||||
if(file.print(message)){
|
||||
Serial.println("File written");
|
||||
} else {
|
||||
Serial.println("Write failed");
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
unsigned long lastStart = 0;
|
||||
|
||||
const int startDelay = 250;
|
||||
|
|
|
|||
16
src/main.cpp
16
src/main.cpp
|
|
@ -88,7 +88,7 @@ void playSongByName(String song) {
|
|||
Serial.println(mp3File.c_str());
|
||||
deactivateRFID();
|
||||
activateSD();
|
||||
audio.connecttoSD(mp3File.c_str());
|
||||
playFile(mp3File.c_str());
|
||||
activateRFID();
|
||||
deactivateSD();
|
||||
}
|
||||
|
|
@ -101,6 +101,18 @@ void playSongByRFID(String id) {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wrapper, so that we can intercept each call for other stuff.
|
||||
*
|
||||
* @param filename
|
||||
* @param resumeFilePos
|
||||
* @return true
|
||||
* @return false
|
||||
*/
|
||||
bool playFile(const char* filename, uint32_t resumeFilePos) {
|
||||
return audio.connecttoSD(filename, resumeFilePos);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void playNextMp3()
|
||||
|
|
@ -123,7 +135,7 @@ void playNextMp3()
|
|||
Serial.println(mp3File.c_str());
|
||||
deactivateRFID();
|
||||
activateSD();
|
||||
audio.connecttoSD(mp3File.c_str());
|
||||
playFile(mp3File.c_str());
|
||||
activateRFID();
|
||||
deactivateSD();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue