2022-08-19 08:37:03 +00:00
|
|
|
#include "playlist.h"
|
2019-11-14 19:42:02 +00:00
|
|
|
|
2022-08-21 09:37:42 +00:00
|
|
|
Playlist::Playlist(String id) {
|
|
|
|
rfid_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
String Playlist::get_rfid_id() {
|
|
|
|
return rfid_id;
|
|
|
|
}
|
|
|
|
|
2022-08-19 08:37:03 +00:00
|
|
|
void Playlist::add_file(String filename) {
|
|
|
|
files.push_back(filename);
|
2019-11-27 05:51:20 +00:00
|
|
|
}
|
|
|
|
|
2022-08-19 08:37:03 +00:00
|
|
|
void Playlist::sort() {
|
|
|
|
std::sort(files.begin(), files.end());
|
2022-08-21 09:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Playlist::set_current_position(uint8_t file, uint32_t seconds) {
|
|
|
|
current_file = file;
|
|
|
|
current_time = seconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
String Playlist::get_current_file_name() {
|
|
|
|
if (current_file >= files.size()) {
|
|
|
|
Serial.printf("Requested a file number %d, which is not available in this playlist. Starting over.\n", current_file);
|
|
|
|
set_current_position(0);
|
|
|
|
}
|
|
|
|
return files[current_file];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Playlist::next_track() {
|
|
|
|
if (files.size() <= current_file + 1) {
|
|
|
|
Serial.println("next_track does not exist. Resetting playlist and returning false.");
|
|
|
|
set_current_position(0, 0);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
set_current_position(current_file + 1, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Playlist::prev_track() {
|
2022-08-21 12:00:52 +00:00
|
|
|
log_d("Playlist::prev_track called. current_file is %d", current_file);
|
2022-08-21 09:37:42 +00:00
|
|
|
if (current_file == 0) {
|
2022-08-21 12:00:52 +00:00
|
|
|
set_current_position(0, 0);
|
|
|
|
} else {
|
|
|
|
set_current_position(current_file - 1, 0);
|
2022-08-21 09:37:42 +00:00
|
|
|
}
|
2022-08-21 13:27:00 +00:00
|
|
|
return files.size()>0;
|
2022-08-21 09:37:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Playlist::restart() {
|
|
|
|
current_time = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Playlist::set_current_time(uint32_t pos) {
|
|
|
|
current_time = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Playlist::get_current_time() {
|
|
|
|
return current_time;
|
2022-08-19 08:37:03 +00:00
|
|
|
}
|