Added playlist create endpoint
This commit is contained in:
@@ -50,7 +50,7 @@ const String apPSK = "aA16161Aa"; // pre-shared-key of access
|
|||||||
// create all needed variables
|
// create all needed variables
|
||||||
int currentVolume = 20; // variable where current volume (0...20) is stored
|
int currentVolume = 20; // variable where current volume (0...20) is stored
|
||||||
String currentSongPath; // path to currently playing song
|
String currentSongPath; // path to currently playing song
|
||||||
bool audioPlaying = true; // play song or not?
|
bool audioPlaying = false; // play song or not?
|
||||||
Audio audio; // Audio object (for playing audio, decoding mp3, ...)
|
Audio audio; // Audio object (for playing audio, decoding mp3, ...)
|
||||||
int currentPlaylistPosition = -1; // the current position in the current playlist
|
int currentPlaylistPosition = -1; // the current position in the current playlist
|
||||||
String currentPlaylist = "/audio/" + directoryPlaylistName + playlistExtension; // path to current playlist
|
String currentPlaylist = "/audio/" + directoryPlaylistName + playlistExtension; // path to current playlist
|
||||||
@@ -65,7 +65,7 @@ struct playbackInfo {
|
|||||||
String resourcePath; // e.g. /audio/XXX.mp3
|
String resourcePath; // e.g. /audio/XXX.mp3
|
||||||
String artist; // e.g. Blender Foundation
|
String artist; // e.g. Blender Foundation
|
||||||
String track; // e.g. 01/02 or 01
|
String track; // e.g. 01/02 or 01
|
||||||
String album;
|
String album; // album
|
||||||
String year; // id3 tag year
|
String year; // id3 tag year
|
||||||
String genre; // id3 tag content type
|
String genre; // id3 tag content type
|
||||||
String copyright; // id3 tag (special)
|
String copyright; // id3 tag (special)
|
||||||
|
@@ -218,6 +218,28 @@ void api_v1_playlist_get() {
|
|||||||
api_server.send(200, "application/json", generate_api_json(true, content));
|
api_server.send(200, "application/json", generate_api_json(true, content));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void api_v1_playlist_create() {
|
||||||
|
Serial.println("[HTTP] [API] 200 - POST '/api/v1/playlist/create'");
|
||||||
|
|
||||||
|
// get the right POST param
|
||||||
|
String folderPath;
|
||||||
|
for (int i = 0; i < api_server.args(); i++) {
|
||||||
|
if (api_server.argName(i) == "folderPath") {
|
||||||
|
folderPath = api_server.arg(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool code = createPlaylistFromDirectory(folderPath);
|
||||||
|
if(code) { // if creating the playlist was successful
|
||||||
|
String playlistPath = folderPath + "/" + directoryPlaylistName + playlistExtension;
|
||||||
|
String content = "\"playlist_path\": \"" + playlistPath + "\"";
|
||||||
|
api_server.send(200, "application/json", generate_api_json(true, content));
|
||||||
|
} else {
|
||||||
|
api_server.send(200, "application/json", generate_api_json(false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void api_v1_settings_restart() {
|
void api_v1_settings_restart() {
|
||||||
SD.end(); // delete SD object and sync its cache to flash
|
SD.end(); // delete SD object and sync its cache to flash
|
||||||
WiFi.disconnect(); // disconnect wifi
|
WiFi.disconnect(); // disconnect wifi
|
||||||
@@ -247,15 +269,16 @@ void setupApiWeb() {
|
|||||||
api_server.send(404, "application/json", "{\"code\": 404, \"message\": \"Resource not found.\"}");
|
api_server.send(404, "application/json", "{\"code\": 404, \"message\": \"Resource not found.\"}");
|
||||||
});
|
});
|
||||||
api_server.on("/", apiRoot);
|
api_server.on("/", apiRoot);
|
||||||
api_server.on("/api/v1/playback/toggle", api_v1_playback_toggle);
|
api_server.on("/api/v1/playback/toggle", HTTP_GET, api_v1_playback_toggle);
|
||||||
api_server.on("/api/v1/playback/play", api_v1_playback_play);
|
api_server.on("/api/v1/playback/play", HTTP_GET, api_v1_playback_play);
|
||||||
api_server.on("/api/v1/playback/pause", api_v1_playback_pause);
|
api_server.on("/api/v1/playback/pause", HTTP_GET, api_v1_playback_pause);
|
||||||
api_server.on("/api/v1/playback/next", api_v1_playback_next);
|
api_server.on("/api/v1/playback/next", HTTP_GET, api_v1_playback_next);
|
||||||
api_server.on("/api/v1/playback/previous", api_v1_playback_previous);
|
api_server.on("/api/v1/playback/previous", HTTP_GET, api_v1_playback_previous);
|
||||||
api_server.on("/api/v1/playback/info", api_v1_playback_info);
|
api_server.on("/api/v1/playback/info", HTTP_GET, api_v1_playback_info);
|
||||||
api_server.on("/api/v1/playlist/get", api_v1_playlist_get);
|
api_server.on("/api/v1/playlist/get", HTTP_GET, api_v1_playlist_get);
|
||||||
api_server.on(UriBraces("/api/v1/volume/{}"), api_v1_playback_volume);
|
api_server.on("/api/v1/playlist/create", HTTP_POST, api_v1_playlist_create);
|
||||||
api_server.on("/api/v1/settings/restart", api_v1_settings_restart);
|
api_server.on(UriBraces("/api/v1/volume/{}"), HTTP_GET, api_v1_playback_volume);
|
||||||
|
api_server.on("/api/v1/settings/restart", HTTP_GET, api_v1_settings_restart);
|
||||||
|
|
||||||
Serial.println("[HTTP] [API] Starting API server (http) on port " + String(webport_api));
|
Serial.println("[HTTP] [API] Starting API server (http) on port " + String(webport_api));
|
||||||
api_server.begin();
|
api_server.begin();
|
||||||
|
Reference in New Issue
Block a user