MP3 TAG READER EXAMPLE
This simple program demonstrate a basic usage of the ID3Tag library to read ID3 Tags embedded in MP3 files.
The program will ask you to select an MP3 file then it will scan this file for ID3 Tags and will show them to the screen, including embedded art if it was found. To quit just hit 'Cancel' on the file requester.
This example is included in the library package.
Here is a screenshot of what you get running this example program:
/* MP3 Tag Reader Program to test the ID3Tag library This program asks for an MP3 file and dumps all the embedded informations including art, if present. To quit hit cancel on the file requester. */ ; Include the ID3 Library @INCLUDE "ID3Tag.hws" ; Setup a display where to dump the ID3 tags @DISPLAY { Width = 640, Height = 480, x = #LEFT, y = #TOP } Local w, h = 640, 480 ; Ask for an mp3 file Local file = FileRequest("Select an MP3 file to scan...", "mp3") ; Setup the font and to shortcuts for the color settings SetFont(#MONOSPACE, 16) Local yel = "[color=#YELLOW]" Local gre = "[color=#GREEN]" ; Main loop While Exists(file) ; Clear the screen and restore cursor position Cls Locate(0, 0) ; Check if an mp3 file has been selected If LowerStr(RightStr(file, 4)) = ".mp3" Local t1, t2, tag1, tag2 = MP3_ID3.Read_ID3(file) Local msg = "" ; If <t1> is True than ID3 v1 tags have been detected If t1 NPrint(yel .. "::: TAGS ID3 v1 :::") ; Dump all the tags found For i, v In Pairs(tag1) NPrint(i .. " : " .. gre .. v) Next EndIf ; If <t2> is True than ID3 v2 tags have been detected If t2 NPrint(yel .. "::: TAGS ID3 v2 :::") ; Dump all the tags found For i, v In Pairs(tag2) ; Check if this tag is an embedded picture, if so save ; its raw data and reload it as a brush, then display ; it to the screen. If i = "rawembeddedpicture" ; Save to a temporary file the raw image data Local fid = OpenFile(Nil, "tmpImage", #MODE_WRITE) WriteString(fid, v.ImageData) CloseFile(fid) ; Load the image as a brush Local bid = LoadBrush(Nil, "tmpImage") ; Remove the temporary file DeleteFile("tmpImage") ; Show the brush DisplayBrush(bid, #RIGHT, #TOP) ; Check if this tag is an UFID field and manage it ElseIf i = "uniquefileidentifier" NPrint("UFID Owner : " .. gre .. v.Owner) NPrint("UFID Code : " .. gre .. v.Identifier) ; In any other case dump the tag contents Else NPrint(i .. " : " .. gre .. v) EndIf Next EndIf Else SystemRequest("WARNING!", "Please select an MP3 file!", "OK") EndIf ; Ask for another file to scan file = FileRequest("Select an MP3 file to scan...", "mp3") Wend