Skip to content

Commit 1d2f750

Browse files
authored
fix coverImage pos if there more than one picture
1 parent f0f5e83 commit 1d2f750

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

src/Audio.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Created on: Oct 26.2018
77
*
8-
* Version 3.0.7r
8+
* Version 3.0.7s
99
* Updated on: Dec 01.2023
1010
* Author: Wolle (schreibfaul1)
1111
*
@@ -1475,6 +1475,7 @@ int Audio::read_FLAC_Header(uint8_t* data, size_t len) {
14751475
//---------------------------------------------------------------------------------------------------------------------
14761476
int Audio::read_ID3_Header(uint8_t* data, size_t len) {
14771477
static size_t id3Size;
1478+
static size_t totalId3Size; // if we have more header, id3_1_size + id3_2_size + ....
14781479
static size_t remainingHeaderBytes;
14791480
static size_t universal_tmp = 0;
14801481
static uint8_t ID3version;
@@ -1483,12 +1484,12 @@ int Audio::read_ID3_Header(uint8_t* data, size_t len) {
14831484
static char frameid[5];
14841485
static size_t framesize = 0;
14851486
static bool compressed = false;
1486-
static bool APIC_seen = false;
1487-
static size_t APIC_size = 0;
1488-
static uint32_t APIC_pos = 0;
1487+
static size_t APIC_size[3] = {0};
1488+
static uint32_t APIC_pos[3] = {0};
14891489
static bool SYLT_seen = false;
14901490
static size_t SYLT_size = 0;
14911491
static uint32_t SYLT_pos = 0;
1492+
static uint8_t numID3Header = 0;
14921493
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14931494
if(m_controlCounter == 0) { /* read ID3 tag and ID3 header size */
14941495
if(getDatamode() == AUDIO_LOCALFILE) {
@@ -1497,7 +1498,6 @@ int Audio::read_ID3_Header(uint8_t* data, size_t len) {
14971498
AUDIO_INFO("Content-Length: %lu", (long unsigned int)m_contentlength);
14981499
}
14991500
m_controlCounter++;
1500-
APIC_seen = false;
15011501
SYLT_seen = false;
15021502
remainingHeaderBytes = 0;
15031503
ehsz = 0;
@@ -1635,9 +1635,9 @@ int Audio::read_ID3_Header(uint8_t* data, size_t len) {
16351635
if(startsWith(tag, "APIC")) { // a image embedded in file, passing it to external function
16361636
isUnicode = false;
16371637
if(getDatamode() == AUDIO_LOCALFILE) {
1638-
APIC_seen = true;
1639-
APIC_pos = id3Size - remainingHeaderBytes;
1640-
APIC_size = framesize;
1638+
APIC_pos[numID3Header] = totalId3Size + id3Size - remainingHeaderBytes;
1639+
APIC_size[numID3Header] = framesize;
1640+
log_e("APIC_pos %i APIC_size %i", APIC_pos[numID3Header], APIC_size[numID3Header]);
16411641
}
16421642
return 0;
16431643
}
@@ -1714,10 +1714,9 @@ int Audio::read_ID3_Header(uint8_t* data, size_t len) {
17141714
m_chbuf[0] = 0;
17151715
if(startsWith(tag, "PIC")) { // image embedded in header
17161716
if(getDatamode() == AUDIO_LOCALFILE) {
1717-
APIC_seen = true; // #460
1718-
APIC_pos = id3Size - remainingHeaderBytes;
1719-
APIC_size = universal_tmp;
1720-
if(m_f_Log) log_i("Attached picture seen at pos %d length %d", APIC_pos, APIC_size);
1717+
APIC_pos[numID3Header] = id3Size - remainingHeaderBytes;
1718+
APIC_size[numID3Header] = universal_tmp;
1719+
if(m_f_Log) log_i("Attached picture seen at pos %d length %d", APIC_pos[0], APIC_size[0]);
17211720
}
17221721
}
17231722
else if(startsWith(tag, "SLT")) { // lyrics embedded in header
@@ -1756,22 +1755,27 @@ int Audio::read_ID3_Header(uint8_t* data, size_t len) {
17561755
// vTaskDelay(30);
17571756
if((*(data + 0) == 'I') && (*(data + 1) == 'D') && (*(data + 2) == '3')) {
17581757
m_controlCounter = 0;
1758+
numID3Header ++;
1759+
totalId3Size += id3Size;
17591760
return 0;
17601761
}
17611762
else {
17621763
m_controlCounter = 100; // ok
17631764
m_audioDataSize = m_contentlength - m_audioDataStart;
17641765
if(!m_f_m3u8data) AUDIO_INFO("Audio-Length: %u", m_audioDataSize);
1765-
if(APIC_seen && audio_id3image) {
1766+
if(APIC_pos[0] && audio_id3image) { // if we have more than one APIC, output the first only
17661767
size_t pos = audiofile.position();
1767-
audio_id3image(audiofile, APIC_pos, APIC_size);
1768+
audio_id3image(audiofile, APIC_pos[0], APIC_size[0]);
17681769
audiofile.seek(pos); // the filepointer could have been changed by the user, set it back
17691770
}
17701771
if(SYLT_seen && audio_id3lyrics) {
17711772
size_t pos = audiofile.position();
17721773
audio_id3lyrics(audiofile, SYLT_pos, SYLT_size);
17731774
audiofile.seek(pos); // the filepointer could have been changed by the user, set it back
17741775
}
1776+
numID3Header = 0;
1777+
for(int i = 0; i< 3; i++) APIC_pos[i] = 0; // delete all
1778+
for(int i = 0; i< 3; i++) APIC_size[i] = 0; // delete all
17751779
return 0;
17761780
}
17771781
}

src/Audio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Created on: Oct 28,2018
55
*
6-
* Version 3.0.7r
6+
* Version 3.0.7s
77
* Updated on: Dec 01.2023
88
* Author: Wolle (schreibfaul1)
99
*/

0 commit comments

Comments
 (0)