GLBasic forum

Codesnippets => Inline / 3rd party => Topic started by: Schranz0r on 2009-Jan-02

Title: Read out the ID3 of a MP3!
Post by: Schranz0r on 2009-Jan-02
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
Title: Read out the ID3 of a MP3!
Post by: Kitty Hello on 2009-Jan-03
Veeeery usefull. Should be moved to "snippets", no?
Title: Read out the ID3 of a MP3!
Post by: Schranz0r on 2009-Jan-03
OK :D