Shuffle the playlist before playing if "[random]" is in the rfid data.
This commit is contained in:
@ -67,7 +67,7 @@ void Controller::handle_rfid() {
|
||||
|
||||
String data = read_rfid_data();
|
||||
|
||||
play(s_uid);
|
||||
play(s_uid, data.indexOf("[random]")>=0);
|
||||
}
|
||||
rfid->PICC_HaltA();
|
||||
}
|
||||
@ -123,10 +123,14 @@ String Controller::read_rfid_data() {
|
||||
return data;
|
||||
}
|
||||
|
||||
void Controller::play(String rfid_id) {
|
||||
void Controller::play(String rfid_id, bool shuffle) {
|
||||
if (!rfid_id.equals(current_playlist.get_rfid_id())) {
|
||||
if (pm->has_playlist(rfid_id)) {
|
||||
current_playlist = pm->get_playlist(rfid_id);
|
||||
if (shuffle) {
|
||||
log_i("Shuffling the playlist.");
|
||||
current_playlist.shuffle();
|
||||
}
|
||||
play();
|
||||
} else {
|
||||
Serial.printf("There is no playlist for rfid_id %s\n", rfid_id.c_str());
|
||||
|
@ -59,4 +59,8 @@ void Playlist::set_current_time(uint32_t pos) {
|
||||
|
||||
uint32_t Playlist::get_current_time() {
|
||||
return current_time;
|
||||
}
|
||||
|
||||
void Playlist::shuffle() {
|
||||
std::random_shuffle(files.begin(), files.end());
|
||||
}
|
Reference in New Issue
Block a user