Playlist: More defensive proramming for when trying to play an empty playlist.
This commit is contained in:
parent
001e275131
commit
dd9e1538c8
@ -36,7 +36,7 @@ public:
|
||||
bool set_track(uint8_t track);
|
||||
void reset();
|
||||
bool is_empty();
|
||||
String get_current_file();
|
||||
bool get_current_file(String* dst);
|
||||
uint32_t get_position();
|
||||
void set_position(uint32_t p);
|
||||
void shuffle(uint8_t random_offset=0);
|
||||
|
@ -535,7 +535,10 @@ bool Player::play() {
|
||||
if (_current_playlist == NULL) return false;
|
||||
if (_current_playlist->get_file_count()==0) return false;
|
||||
_current_playlist->start();
|
||||
String file = _current_playlist->get_current_file();
|
||||
String file;
|
||||
if (!_current_playlist->get_current_file(&file)) {
|
||||
return false;
|
||||
}
|
||||
uint32_t position = _current_playlist->get_position();
|
||||
_state = playing;
|
||||
_play_file(file, position);
|
||||
|
@ -310,8 +310,13 @@ void Playlist::reset() {
|
||||
_started = false;
|
||||
}
|
||||
|
||||
String Playlist::get_current_file() {
|
||||
return _files[_current_track].filename;
|
||||
bool Playlist::get_current_file(String* dst) {
|
||||
if (_current_track < _files.size()) {
|
||||
return false;
|
||||
} else {
|
||||
dst->concat(_files[_current_track].filename);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Playlist::get_position() {
|
||||
|
Loading…
Reference in New Issue
Block a user