Shuffle the playlist before playing if "[random]" is in the rfid data.
This commit is contained in:
parent
15a65f7391
commit
13e62fea19
@ -19,13 +19,13 @@ class Controller {
|
|||||||
unsigned long button_pressed_since = 0;
|
unsigned long button_pressed_since = 0;
|
||||||
bool button_already_processed = false;
|
bool button_already_processed = false;
|
||||||
String read_rfid_data();
|
String read_rfid_data();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void handle();
|
void handle();
|
||||||
void next_track();
|
void next_track();
|
||||||
void prev_track();
|
void prev_track();
|
||||||
void play();
|
void play();
|
||||||
void play(String rfid_id);
|
void play(String rfid_id, bool shuffle=false);
|
||||||
void stop();
|
void stop();
|
||||||
void eof_mp3();
|
void eof_mp3();
|
||||||
};
|
};
|
@ -22,4 +22,5 @@ class Playlist {
|
|||||||
void restart();
|
void restart();
|
||||||
void set_current_time(uint32_t time);
|
void set_current_time(uint32_t time);
|
||||||
uint32_t get_current_time();
|
uint32_t get_current_time();
|
||||||
|
void shuffle();
|
||||||
};
|
};
|
||||||
|
@ -67,7 +67,7 @@ void Controller::handle_rfid() {
|
|||||||
|
|
||||||
String data = read_rfid_data();
|
String data = read_rfid_data();
|
||||||
|
|
||||||
play(s_uid);
|
play(s_uid, data.indexOf("[random]")>=0);
|
||||||
}
|
}
|
||||||
rfid->PICC_HaltA();
|
rfid->PICC_HaltA();
|
||||||
}
|
}
|
||||||
@ -123,10 +123,14 @@ String Controller::read_rfid_data() {
|
|||||||
return 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 (!rfid_id.equals(current_playlist.get_rfid_id())) {
|
||||||
if (pm->has_playlist(rfid_id)) {
|
if (pm->has_playlist(rfid_id)) {
|
||||||
current_playlist = pm->get_playlist(rfid_id);
|
current_playlist = pm->get_playlist(rfid_id);
|
||||||
|
if (shuffle) {
|
||||||
|
log_i("Shuffling the playlist.");
|
||||||
|
current_playlist.shuffle();
|
||||||
|
}
|
||||||
play();
|
play();
|
||||||
} else {
|
} else {
|
||||||
Serial.printf("There is no playlist for rfid_id %s\n", rfid_id.c_str());
|
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() {
|
uint32_t Playlist::get_current_time() {
|
||||||
return current_time;
|
return current_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Playlist::shuffle() {
|
||||||
|
std::random_shuffle(files.begin(), files.end());
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user