esmp3/src/playlist.cpp

62 lines
1.3 KiB
C++

#include "playlist.h"
Playlist::Playlist(String id) {
rfid_id = id;
}
String Playlist::get_rfid_id() {
return rfid_id;
}
void Playlist::add_file(String filename) {
files.push_back(filename);
}
void Playlist::sort() {
std::sort(files.begin(), files.end());
}
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() {
log_d("Playlist::prev_track called. current_file is %d", current_file);
if (current_file == 0) {
set_current_position(0, 0);
} else {
set_current_position(current_file - 1, 0);
}
return files.size()>0;
}
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;
}