Read out the ID3 of a MP3!

Previous topic - Next topic

Schranz0r

Hey if you need to read out the ID3 for a mp3 to get the name, album, year ...

You can use this:

Code (glbasic) Select
FUNCTION GetID3: file$, BYREF title$, BYREF artist$, BYREF album$, BYREF year$, BYREF comment$, BYREF genre$
DIM bytearray%[128]
LOCAL check_tag$
OK = OPENFILE(0, file$, TRUE)

IF OK
FILESEEK 0, -128, -1
FOR i = 0 TO 127
READBYTE 0, bytearray[i]
NEXT
CLOSEFILE 0
ENDIF


// Read TAG
FOR i = 0 TO 2
check_tag$ = check_tag$ + CHR$(bytearray[i])
NEXT


IF check_tag$ = "TAG"
// Read title
FOR i = 3 TO 32
title$ = title$ + CHR$(bytearray[i])
NEXT
// Read artist
FOR i = 33 TO 62
artist$ = artist$ + CHR$(bytearray[i])
NEXT
// Read album
FOR i = 63 TO 92
album$ = album$ + CHR$(bytearray[i])
NEXT
// Read year
FOR i = 93 TO 96
year$ = year$ + CHR$(bytearray[i])
NEXT
// Read comment
FOR i = 97 TO 126
comment$ = comment$ + CHR$(bytearray[i])
NEXT
// Read genre
genre$ = CHR$(bytearray[127])
ENDIF
ENDFUNCTION
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Kitty Hello

Veeeery usefull. Should be moved to "snippets", no?

Schranz0r

I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard