Skip ID3 tags. They can get quite large...

This commit is contained in:
Fabian Schlenz 2019-08-12 06:20:38 +02:00
parent f29e38160a
commit b5c29eaa38
2 changed files with 29 additions and 1 deletions

View File

@ -52,6 +52,7 @@ private:
void _set_last_track(const char* album, uint8_t track, uint32_t position);
std::map<String, album_state> _last_tracks;
void _play_file(String filename, uint32_t offset);
uint32_t _id3_tag_offset(File f);
void _finish_playing();
void _finish_stopping();
void _mute();

View File

@ -334,13 +334,40 @@ void Player::_play_file(String file, uint32_t file_offset) {
_write_control_register(SCI_STATUS, _read_control_register(SCI_STATUS) & ~SS_DO_NOT_JUMP);
delay(100);
if (file_offset == 0) {
_file.seek(_id3_tag_offset(_file));
}
_refills = 0;
_current_play_position = 0;
_current_play_position = _file.position();
_skip_to = file_offset;
if (_skip_to>0) _mute();
INFO("Now playing.\n");
}
uint32_t Player::_id3_tag_offset(File f) {
uint32_t original_position = f.position();
uint32_t offset = 0;
if (f.read()=='I' && f.read()=='D' && f.read()=='3') {
DEBUG("ID3 tag found\n");
// Skip ID3 tag version
f.read(); f.read();
byte tags = f.read();
bool footer_present = tags & 0x10;
DEBUG("ID3 footer found: %d\n", footer_present);
for (byte i=0; i<4; i++) {
offset <<= 7;
offset |= (0x7F & f.read());
}
offset += 10;
if (footer_present) offset += 10;
DEBUG("ID3 tag length is %d bytes.\n", offset);
} else {
DEBUG("No ID3 tag found\n");
}
f.seek(original_position);
return offset;
}
void Player::_flush(uint count, int8_t byte) {
SPIMaster::enable(XDCS);
SPI.beginTransaction(*_spi_settings);