Skip to content

Commit

Permalink
update v1.1 20/03/2023
Browse files Browse the repository at this point in the history
- better thumbnail detection in jpeg
  pattern ffd8 ffd8 ffd9 ffd9 next to
  pattern ffd8 ffd9 ffd8 ffd9
- better png check using exif as check
- removed p play option not really needed
- misc bugfixes stability and error handling
  • Loading branch information
thrive4 committed Mar 21, 2023
1 parent 720b824 commit d15e023
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
8 changes: 4 additions & 4 deletions app.rc
Expand Up @@ -10,8 +10,8 @@ FB_PROGRAM_ICON ICON "f:\dev\freebasic\projects\audioplayer-sdlmixer\app.ico"

// add version and file info in exe windows only
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1, 0, 0, 000
PRODUCTVERSION 1, 0, 0, 0
FILEVERSION 1, 1, 0, 000
PRODUCTVERSION 1, 1, 0, 0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x9L
Expand All @@ -29,13 +29,13 @@ BEGIN
VALUE "Comments", "needs sdl2 and sdl2 mixer libs"
VALUE "CompanyName", ""
VALUE "FileDescription", "audioplayer with sdl2 mixer"
VALUE "FileVersion", "1, 0, 0, 000"
VALUE "FileVersion", "1, 1, 0, 000"
VALUE "InternalName", ""
VALUE "LegalCopyright", ""
VALUE "OriginalFilename", "audioplayer"
VALUE "PrivateBuild", ""
VALUE "ProductName", "audioplayer"
VALUE "ProductVersion", "1, 0, 0, 0"
VALUE "ProductVersion", "1, 1, 0, 0"
END
END
BLOCK "VarFileInfo"
Expand Down
26 changes: 19 additions & 7 deletions audioplayer.bas
Expand Up @@ -270,10 +270,21 @@ Function getmp3cover(filename As String) As boolean
bend = instr(1, mid(buffer, instr(1, buffer, "JFIF")), CHR(&hFF, &hD9)) + 7
end if
chunk = mid(buffer, instr(buffer, "JFIF") - 6, bend)
' thumbnail detection
if instr(instr(1, buffer, "JFIF") + 4, buffer, "JFIF") > 0 then
chunk = mid(buffer, instr(10, buffer, CHR(&hFF, &hD8)), instr(instr(buffer, CHR(&hFF, &hD9)) + 1, buffer, CHR(&hFF, &hD9)) - (instr(10, buffer, CHR(&hFF, &hD8)) - 2))
' thumbnail in thumbnail edge case ffd8 ffd8 ffd9 ffd9 pattern in jpeg
if instr(chunk, CHR(&hFF, &hD8, &hFF)) > 0 then
chunk = mid(buffer,_
instr(1,buffer, CHR(&hFF, &hD8)),_
instr(instr(instr(instr(1,buffer, CHR(&hFF, &hD9)) + 1, buffer, CHR(&hFF, &hD9)) + 1, buffer, CHR(&hFF, &hD9))_
, buffer, CHR(&hFF, &hD9)) + 2 - instr(buffer, CHR(&hFF, &hD8)))
end if
end if
ext = ".jpg"
end if
' use ext to catch false png
if instr(1, buffer, "‰PNG") > 0 and ext = "" then
' use ext and exif check to catch false png
if instr(1, buffer, "‰PNG") > 0 and instr(1, buffer, "Exif") = 0 and ext = "" then
' override end png if tag is present
if instr(1, buffer, "IEND") > 0 then
bend = instr(1, mid(buffer, instr(1, buffer, "‰PNG")), "IEND") + 7
Expand All @@ -294,6 +305,12 @@ Function getmp3cover(filename As String) As boolean
end if
ext = ".jpg"
end if
' last resort just check on begin and end marker very tricky...
' see https://stackoverflow.com/questions/4585527/detect-end-of-file-for-jpg-images#4614629
if instr(buffer, CHR(&hFF, &hD8)) > 0 and ext = ""then
chunk = mid(buffer, instr(1, buffer, CHR(&hFF, &hD8)), instr(1, buffer, CHR(&hFF, &hD9)))
ext = ".jpg"
end if
buffer = ""
Close #1
' attempt to write thumbnail to temp file
Expand Down Expand Up @@ -405,10 +422,6 @@ Do
Dim As String key = UCase(Inkey)

Select Case key
Case "P"
' play mp3
Mix_PlayMusic(music,0)
tracklength = Mix_MusicDuration(music)
Case Chr$(32)
' toggle mp3 mute status
If musicstate Then
Expand Down Expand Up @@ -500,7 +513,6 @@ Do
Locate currentLine, 1
' basic interaction
Print "===== > SDL2 mixer library demonstration < ====="
Print "press p play"
Print "press . play next"
Print "press , play previous"
Print "press ] skip forward 10 secs"
Expand Down
1 change: 0 additions & 1 deletion help-de.ini
Expand Up @@ -20,7 +20,6 @@ coverart von mp3 wird als thumb.jpg oder thumb.png extrahiert

> navigation <

p : Spielen
. : als nächstes spielen
, : Zurück abspielen
] : 10 Sekunden vorwärts springen
Expand Down
1 change: 0 additions & 1 deletion help-en.ini
Expand Up @@ -19,7 +19,6 @@ coverart of mp3 is extracted as thumb.jpg or thumb.png

> navigation <

p : play
. : play next
, : play previous
] : skip forward 10 secs
Expand Down
1 change: 0 additions & 1 deletion readme.md
Expand Up @@ -59,7 +59,6 @@ threads 4 / 7\
cpu ~1 (low) / ~2\
tested on intel i5-6600T
## navigation
press p to play\
press . to play next\
press , to play previous\
press ] to skip forward 10 secs\
Expand Down

0 comments on commit d15e023

Please sign in to comment.