Go Back   Winamp Forums > Developer Center > Winamp Development

Reply
Thread Tools Search this Thread Display Modes
Old 7th October 2003, 12:34   #1
MicMeo
Junior Member
 
Join Date: Oct 2003
Location: VietNam
Posts: 1
Send a message via Yahoo to MicMeo
ID3v2 Programming with VB ! How to do? And what infos I need to do ?

ID3v2 Programming with VB ! How to do? And what infos I need to do ?
To get infomations in COMMENTS tag of and MP3 ID3v2 file . I's put lyrics in there and now I want to get it and send to a screen ! I think I need a plugin ! But I dont know where to start !!!!
Help me Plz ....

You could post your Reply here or mail to me at : micmeo82@yahoo.com

Thanks !
MicMeo is offline   Reply With Quote
Old 12th October 2003, 15:14   #2
albator2000
Junior Member
 
Join Date: Oct 2003
Location: South France
Posts: 15
there's a class module I use for that :

code:
Option Explicit
Option Base 1
Private Type CLASS_ID3_Tag
Titre As String * 30
Artiste As String * 30
Album As String * 30
Année As String * 4
Commentaire As String * 30
Genre As Byte
End Type

Public Type CLASS_CORRECTED_ID3_Tag
Titre As String
Artiste As String
Album As String
Année As String
Commentaire As String
Genre As Byte
ID3Version As String
End Type

Function GetMP3Tag(Fichier As String) As CLASS_CORRECTED_ID3_Tag
Dim FreeSlot As Integer
Dim Lect As String * 3
Dim ID3TagReaded As CLASS_ID3_Tag
Dim Id3Header(7) As Byte
Dim Id3TagSize As Long
Dim BitMapTemp() As Byte
Dim BitMap() As Byte
Dim Compteur As Integer
Dim Compteur2 As Integer
Dim index As Byte
Dim ExtendedHeader As Boolean

Dim CurIndex As Long
Dim strTemp As String
'frame header
Dim FrameID As String * 4
Dim FrameSize As Long
Dim FrameFlags As Integer

FreeSlot = FreeFile
Open Fichier For Binary As FreeSlot
Get FreeSlot, 1, Lect
If Lect = "ID3" Then
'juste la premiere version, qui englobe
'à peut pret tout
GetMP3Tag.ID3Version = "v2.1"
Get FreeSlot, 4, Id3Header
If Id3Header(1) = 3 Then
If Id3Header(3) And 128 Then
' Unsynchronisation
End If
If Id3Header(3) And 64 Then
'Extended header
ExtendedHeader = True
End If
If Id3Header(3) And 32 Then
'Experimental indicator
End If
If Id3Header(3) And 31 Then
'doivent être 0!!!
End If
' '***** TEST
' Id3Header(4) = 0
' Id3Header(5) = 0
' Id3Header(6) = 2
' Id3Header(7) = 1
' '***** TEST
For Compteur = 7 To 4 Step -1
DecToBin Id3Header(Compteur), BitMapTemp()
Debug.Assert Not (BitMapTemp(7))
ReDim Preserve BitMapTemp(0 To UBound(BitMapTemp()) - 1)
For Compteur2 = 0 To UBound(BitMapTemp())
ReDim Preserve BitMap(0 To index + UBound(BitMapTemp()))
BitMap(index + Compteur2) = BitMapTemp(Compteur2)
Next Compteur2
index = index + UBound(BitMapTemp()) + 1
Next Compteur
BinToDec BitMap, Id3TagSize
If ExtendedHeader Then
'TODO: Passer le tag extensed
End If
CurIndex = 11
Do While CurIndex < Id3TagSize
Get FreeSlot, CurIndex, FrameID
'si je suis HexWorkShop, les 4 octets sont codé "à l'envers, big endian(motorola),ché pas koi"!!
'donc, c'est galère, il faut que j'inverse les octets entre eux

Get FreeSlot, CurIndex + 4, FrameSize
DecToBin FrameSize, BitMapTemp()
ReDim BitMap(0 To UBound(BitMapTemp))
For Compteur = 0 To 31 Step 8
'BitMap(Compteur) = BitMapTemp(23 - Compteur)
For Compteur2 = 0 To 7
BitMap(Compteur + Compteur2) = BitMapTemp(24 - Compteur + Compteur2)
Next Compteur2
Next
BinToDec BitMap(), FrameSize
Get FreeSlot, CurIndex + 8, FrameFlags
CurIndex = CurIndex + 4 + 4 + 2
If FrameID <> String(4, Chr(0)) Then
strTemp = String(FrameSize - 1, " ")
Get FreeSlot, CurIndex + 1, strTemp
Debug.Print FrameID
Debug.Print strTemp
End If

Select Case FrameID
Case "TALB"
strTemp = String(FrameSize - 1, " ")
Get FreeSlot, CurIndex + 1, strTemp
GetMP3Tag.Album = Trim(strTemp)
Case "TIT2"
strTemp = String(FrameSize - 1, " ")
Get FreeSlot, CurIndex + 1, strTemp
GetMP3Tag.Titre = Trim(strTemp)
Case "TPE1"
strTemp = String(FrameSize - 1, " ")
Get FreeSlot, CurIndex + 1, strTemp
GetMP3Tag.Artiste = Trim(strTemp)
Case "TPE4"
strTemp = String(FrameSize - 1, " ")
Get FreeSlot, CurIndex + 1, strTemp
GetMP3Tag.Artiste = Trim(strTemp)
Case "COMM"
strTemp = String(FrameSize - 1, " ")
Get FreeSlot, CurIndex + 1, strTemp
GetMP3Tag.Commentaire = Trim(Replace(strTemp, Chr(0), Chr(32)))
Case "TCON"
strTemp = String(FrameSize - 1, " ")
Get FreeSlot, CurIndex + 1, strTemp
'GetMP3Tag.Genre = Trim(strTemp) type incompatible
Case "TYER"
strTemp = String(FrameSize - 1, " ")
Get FreeSlot, CurIndex + 1, strTemp
GetMP3Tag.Année = Trim(strTemp)

Case Else
'MsgBox FrameID
End Select
CurIndex = CurIndex + FrameSize
Loop
End If
Else
'la version "banale" du tag
GetMP3Tag.ID3Version = "v1"
Get FreeSlot, (LOF(FreeSlot) - 127), Lect
If UCase(Lect) = "TAG" Then
Get FreeSlot, (LOF(FreeSlot) - 124), ID3TagReaded
GetMP3Tag.Titre = RectifieTexte(ID3TagReaded.Titre)
GetMP3Tag.Artiste = RectifieTexte(ID3TagReaded.Artiste)
GetMP3Tag.Album = RectifieTexte(ID3TagReaded.Album)
GetMP3Tag.Année = RectifieTexte(ID3TagReaded.Année)
GetMP3Tag.Commentaire = RectifieTexte(ID3TagReaded.Commentaire)
GetMP3Tag.Genre = ID3TagReaded.Genre
End If
End If
Close FreeSlot
End Function

Public Sub ExtractID3TagFromFileName(ByVal filename As String, ByRef Titre As String, ByRef Artiste As String, ByRef Album As String)

Dim intIndexTiret As Integer
Dim intLastFound As Integer
Dim intNbFound As Integer
Dim strFound() As String


intIndexTiret = InStr(1, filename, ".")
Do While intIndexTiret <> 0
intLastFound = intIndexTiret
intIndexTiret = InStr(intIndexTiret + 1, filename, ".")
Loop

filename = Left(filename, intLastFound - 1) & "-"

'Dim intIndexLBracket As Integer
'Dim intIndexRBracket As Integer


'intIndexLBracket = InStr(1, FileName, "[")
'If intIndexLBracket <> 0 Then
' intIndexRBracket = InStr(intIndexLBracket + 2, FileName, "]")
' If intIndexRBracket <> 0 Then

intLastFound = 1
intIndexTiret = InStr(intLastFound, filename, "-")
Do While intIndexTiret <> 0
intNbFound = intNbFound + 1
ReDim Preserve strFound(1 To intNbFound)
strFound(intNbFound) = Mid(filename, intLastFound, intIndexTiret - intLastFound)
intLastFound = intIndexTiret + 1
intIndexTiret = InStr(intLastFound + 1, filename, "-")
Loop
For intIndexTiret = 1 To intNbFound
If intIndexTiret = intNbFound Then
If Titre = "" Then Titre = Trim(strFound(intIndexTiret))
Else
Select Case intIndexTiret
Case 1
If Artiste = "" Then Artiste = Trim(strFound(intIndexTiret))
Case 2
If Album = "" Then Album = Trim(strFound(intIndexTiret))
Case Else
' ExtractID3TagFromFileName = ExtractID3TagFromFileName & strFound(intIndexTiret)
End Select
End If
Next intIndexTiret
End Sub
Public Sub DecToBin(Dec, ByRef Bin() As Byte)
Dim Compteur As Integer
Dim index As Integer
Dim Max As Integer
Dim Temp As Integer
Select Case TypeName(Dec)
Case "Byte": Max = 7
Case "Integer": Max = 15
Case "Long": Max = 31
Case Else
Do While 2 ^ index <= Dec
index = index + 1
Loop
Max = Int(((index - 1) / 8) + 1) * 8 - 1
End Select

ReDim Bin(0 To Max)

If Dec <> 0 Then
For index = Max To 0 Step -1
If 2 ^ index <= Dec Then
Bin(index) = 1
Dec = Dec - 2 ^ index
End If
Next index
End If
End Sub

Public Sub BinToDec(Bin() As Byte, Dec)
Dim Compteur As Integer
For Compteur = 0 To UBound(Bin())
Dec = Dec + Bin(Compteur) * (2 ^ Compteur)
Next Compteur
End Sub

Function RectifieTexte(Texte As String) As String
Dim intIndex As Integer
intIndex = InStr(1, Texte, Chr(0))
If intIndex <> 0 Then
Texte = Left(Texte, intIndex - 1)
Else
Texte = Texte
End If
RectifieTexte = Trim(Texte)
End Function



then in your source code simple declare :

code:
Private m_cID3v1 As New cMP3ID3v1
Private m_cID3v2 As New cMP3ID3v2



and use it like that :

code:
' ID3v1 Tag Information:
With m_cID3v1
.MP3File = track.Text
Text1.Text = .Artist
Text2.Text = .Title
Text3.Text = .Album
End With

With m_cID3v2
.MP3File = track.Text
Text1.Text = .Artist
Text2.Text = .Title
Text3.Text = .Album
End With



albator2000 is offline   Reply With Quote
Old 13th October 2003, 12:35   #3
albator2000
Junior Member
 
Join Date: Oct 2003
Location: South France
Posts: 15
err... no that's wrong

Tonight i'll post two class (ID3 v1 & v2) to access and write ID3 tags.

sorry for this mystake...
albator2000 is offline   Reply With Quote
Old 13th October 2003, 15:59   #4
albator2000
Junior Member
 
Join Date: Oct 2003
Location: South France
Posts: 15
ok so here it is

class cMP3ID3v1 :
code:
Option Explicit

'
' cMP3ID3v1.cls
' Read and Write MP3 ID3 v1 tags.
'
' http://vbaccelerator.com/
' S McMahon
' 2003-01-26
'
' Updates
' 2003/05/07: Added ID3 v1.1 support.
' Thanks to Don Beal for providing the code!
'


Private Type MP3ID3V1Tag
Tag As String * 3 '-- 03
Title As String * 30 '-- 33
Artist As String * 30 '-- 63
Album As String * 30 '-- 93
Year As String * 4 '-- 97
Comment As String * 28 '-- 125
' START: Mods for ID3 v1.1 support
Filler As Byte '-- 126
Track As Byte '-- 127
' END: Mods for ID3 v1.1. support
Genre As Byte '-- 128
End Type

Private m_sMp3File As String

Private m_bHasID3v1Tag As Boolean

Private m_sTag As String
Private m_sTitle As String
Private m_sArtist As String
Private m_sAlbum As String
Private m_sYear As String
Private m_sComment As String
Private m_sGenre As Byte
' Added for ID3 v1.1 support:
Private m_sTrack As Byte


Public Property Get MP3File() As String
MP3File = m_sMp3File
End Property

Public Property Let MP3File(ByVal value As String)
m_sMp3File = value
pLoadTag
End Property

Public Sub Update()
pUpdateTag
End Sub

Public Property Get HasID3v1Tag() As Boolean
HasID3v1Tag = m_bHasID3v1Tag
End Property

Public Property Get Title() As String
Title = m_sTitle
End Property
Public Property Let Title(ByVal value As String)
m_sTitle = value
End Property

Public Property Get Artist() As String
Artist = m_sArtist
End Property
Public Property Let Artist(ByVal value As String)
m_sArtist = value
End Property

Public Property Get Album() As String
Album = m_sAlbum
End Property
Public Property Let Album(ByVal value As String)
m_sAlbum = value
End Property

Public Property Get Year() As String
Year = m_sYear
End Property
Public Property Let Year(ByVal value As String)
m_sYear = value
End Property

' START: Added for ID3 v1.1 support.
Public Property Get Track() As Byte
Track = m_sTrack
End Property
Public Property Let Track(ByVal value As Byte)
m_sTrack = value
End Property
' END: Added for ID3 v1.1 support.

Public Property Get Comment() As String
Comment = m_sComment
End Property
Public Property Let Comment(ByVal value As String)
m_sComment = value
End Property

Public Property Get Genre() As Byte
Genre = m_sGenre
End Property
Public Property Let Genre(ByVal value As Byte)
m_sGenre = value
End Property

Public Property Get GenreName(ByVal Genre As Byte) As String
Dim sName As String
Select Case Genre
Case 34: sName = "Acid"
Case 74: sName = "Acid Jazz"
Case 73: sName = "Acid Punk"
Case 99: sName = "Acoustic"
Case 40: sName = "Alt.Rock"
Case 20: sName = "Alternative"
Case 26: sName = "Ambient"
Case 145: sName = "Anime"
Case 90: sName = "Avant Garde"
Case 116: sName = "Ballad"
Case 41: sName = "Bass"
Case 135: sName = "Beat"
Case 85: sName = "Bebob"
Case 96: sName = "Big Band"
Case 138: sName = "Black Metal"
Case 89: sName = "Blue Grass"
Case 0: sName = "Blues"
Case 107: sName = "Booty Bass"
Case 132: sName = "Brit Pop"
Case 65: sName = "Cabaret"
Case 88: sName = "Celtic"
Case 104: sName = "Chamber Music"
Case 102: sName = "Chanson"
Case 97: sName = "Chorus"
Case 136: sName = "Christian Gangsta Rap"
Case 61: sName = "Christian Rap"
Case 141: sName = "Christian Rock"
Case 1: sName = "Classic Rock"
Case 32: sName = "Classical"
Case 112: sName = "Club"
Case 128: sName = "Club - House"
Case 57: sName = "Comedy"
Case 140: sName = "Contemporary Christian"
Case 2: sName = "Country"
Case 139: sName = "Crossover"
Case 58: sName = "Cult"
Case 3: sName = "Dance"
Case 125: sName = "Dance Hall"
Case 50: sName = "Darkwave"
Case 22: sName = "Death Metal"
Case 4: sName = "Disco"
Case 55: sName = "Dream"
Case 127: sName = "Drum & Bass"
Case 122: sName = "Drum Solo"
Case 120: sName = "Duet"
Case 98: sName = "Easy Listening"
Case 52: sName = "Electronic"
Case 48: sName = "Ethnic"
Case 54: sName = "Eurodance"
Case 124: sName = "Euro - House"
Case 25: sName = "Euro - Techno"
Case 84: sName = "Fast Fusion"
Case 80: sName = "Folk"
Case 81: sName = "Folk / Rock"
Case 115: sName = "Folklore"
Case 119: sName = "Freestyle"
Case 5: sName = "Funk"
Case 30: sName = "Fusion"
Case 36: sName = "Game"
Case 59: sName = "Gangsta Rap"
Case 126: sName = "Goa"
Case 38: sName = "Gospel"
Case 49: sName = "Gothic"
Case 91: sName = "Gothic Rock"
Case 6: sName = "Grunge"
Case 79: sName = "Hard Rock"
Case 129: sName = "Hardcore"
Case 137: sName = "Heavy Metal"
Case 7: sName = "Hip Hop"
Case 35: sName = "House"
Case 100: sName = "Humour"
Case 131: sName = "Indie"
Case 19: sName = "Industrial"
Case 33: sName = "Instrumental"
Case 46: sName = "Instrumental Pop"
Case 47: sName = "Instrumental Rock"
Case 8: sName = "Jazz"
Case 29: sName = "Jazz - Funk"
Case 146: sName = "JPop"
Case 63: sName = "Jungle"
Case 86: sName = "Latin"
Case 71: sName = "Lo - fi"

Case 45: sName = "Meditative"
Case 142: sName = "Merengue"
Case 9: sName = "Metal"
Case 77: sName = "Musical"
Case 82: sName = "National Folk"

Case 64: sName = "Native American"
Case 133: sName = "Negerpunk"
Case 10: sName = "New Age"
Case 66: sName = "New Wave"

Case 39: sName = "Noise"
Case 11: sName = "Oldies"

Case 103: sName = "Opera"
Case 12: sName = "Other"
Case 75: sName = "Polka"
Case 134: sName = "Polsk Punk"

Case 13: sName = "Pop"
Case 62: sName = "Pop / Funk"
Case 53: sName = "Pop / Folk"
Case 109: sName = "Pr0n Groove"

Case 117: sName = "Power Ballad"
Case 23: sName = "Pranks"
Case 108: sName = "Primus"
Case 92: sName = "Progressive Rock"
Case 67: sName = "Psychedelic"
Case 93: sName = "Psychedelic Rock"

Case 43: sName = "Punk"
Case 121: sName = "Punk Rock"
Case 14: sName = "R&B"
Case 15: sName = "Rap"

Case 68: sName = "Rave"
Case 16: sName = "Reggae"
Case 76: sName = "Retro"
Case 87: sName = "Revival"
Case 118: sName = "Rhythmic Soul"

Case 17: sName = "Rock"
Case 78: sName = "Rock 'n'Roll"
Case 143: sName = "Salsa"
Case 114: sName = "Samba"
Case 110: sName = "Satire"
Case 69: sName = "Showtunes"
Case 21: sName = "Ska"
Case 111: sName = "Slow Jam"

Case 95: sName = "Slow Rock"
Case 105: sName = "Sonata"
Case 42: sName = "Soul"
Case 37: sName = "Sound Clip"
Case 24: sName = "Soundtrack"
Case 56: sName = "Southern Rock"
Case 44: sName = "Space"
Case 101: sName = "Speech"
Case 83: sName = "Swing"
Case 94: sName = "Symphonic Rock"
Case 106: sName = "Symphony"
Case 147: sName = "Synth Pop"

Case 113: sName = "Tango"
Case 18: sName = "Techno"
Case 51: sName = "Techno - Industrial"
Case 130: sName = "Terror"
Case 144: sName = "Thrash Metal"
Case 60: sName = "Top 40"
Case 70: sName = "Trailer"

Case 31: sName = "Trance"
Case 72: sName = "Tribal"

Case 27: sName = "Trip Hop"
Case 28: sName = "Vocal"

End Select
GenreName = sName
End Property

Private Sub pLoadTag()
Dim iFile As Integer
Dim lErr As Long
Dim sErr As String

m_bHasID3v1Tag = False
m_sComment = ""
m_sArtist = ""
m_sAlbum = ""
m_sYear = ""
m_sGenre = 255
m_sTitle = ""
' Added for ID3 v1.1 support:
m_sTrack = 0

iFile = FreeFile
On Error Resume Next
Open m_sMp3File For Binary Access Read Lock Write As #iFile
If (E******mber <> 0) Then
lErr = E******mber
sErr = Err.Description
On Error GoTo 0
Err.Raise lErr, App.EXEName & ".cMP3ID3v1", sErr
Else
On Error GoTo 0
If LOF(iFile) > 128 Then
Dim Tag As MP3ID3V1Tag
Get #iFile, LOF(iFile) - 127, Tag.Tag
If Not (StrComp(Tag.Tag, "TAG") = 0) Then
' no tag
Else
m_bHasID3v1Tag = True
Get #iFile, , Tag.Title
m_sTitle = Tag.Title
Get #iFile, , Tag.Artist
m_sArtist = Tag.Artist
Get #iFile, , Tag.Album
m_sAlbum = Tag.Album
Get #iFile, , Tag.Year
m_sYear = Tag.Year
Get #iFile, , Tag.Comment
m_sComment = Tag.Comment
' START: Added for ID3 v1.1 support:
Get #iFile, , Tag.Filler
Get #iFile, , Tag.Track
m_sTrack = Tag.Track
' END: added for ID3 v1.1 support
Get #iFile, , Tag.Genre
m_sGenre = Tag.Genre

End If
End If
End If
On Error Resume Next
Close #iFile
On Error GoTo 0
Err.Clear

End Sub
Private Sub pUpdateTag()
Dim iFile As Integer
Dim lErr As Long
Dim sErr As String
iFile = FreeFile
On Error Resume Next
Open m_sMp3File For Binary Access Read Write Lock Write As #iFile
If (E******mber <> 0) Then
lErr = E******mber
sErr = Err.Description
On Error GoTo 0
Err.Raise lErr, App.EXEName & ".cMP3ID3v1", sErr
Else
Dim Tag As MP3ID3V1Tag
If LOF(iFile) > 0 Then
If LOF(iFile) > 128 Then
Get #iFile, LOF(iFile) - 127, Tag.Tag
If Not (StrComp(Tag.Tag, "TAG") = 0) Then
' no MP3 tag already, need to extend the file
' to add it
Seek #iFile, LOF(iFile)
Tag.Tag = "TAG"
Put #iFile, , Tag.Tag
End If
LSet Tag.Title = m_sTitle
LSet Tag.Artist = m_sArtist
LSet Tag.Album = m_sAlbum
LSet Tag.Year = m_sYear
' START: added for ID3 v1.1 support
Tag.Track = m_sTrack
' END: added for ID3 v1.1 support
LSet Tag.Comment = m_sComment
Tag.Genre = m_sGenre

Put #iFile, , Tag.Title
Put #iFile, , Tag.Artist
Put #iFile, , Tag.Album
Put #iFile, , Tag.Year
Put #iFile, , Tag.Comment
' START: added for ID3 v1.1 support
Put #iFile, , Tag.Filler
Put #iFile, , Tag.Track
' END: added for ID3 v1.1 support
Put #iFile, , Tag.Genre

End If
Else
On Error Resume Next
Close #iFile
On Error GoTo 0
Err.Raise vbObjectError + 4097, App.EXEName & ".cMP3ID3v1", m_sMp3File & " is not a valid MP3 file."
End If
End If

On Error Resume Next
Close #iFile
On Error GoTo 0
Err.Clear

End Sub

albator2000 is offline   Reply With Quote
Old 13th October 2003, 16:01   #5
albator2000
Junior Member
 
Join Date: Oct 2003
Location: South France
Posts: 15
the MP3ID3v2 is longer so i've put cMP3ID3v1 + cMP3ID3v2 into a zip file attached to the next post

enjoy
albator2000 is offline   Reply With Quote
Old 13th October 2003, 16:04   #6
albator2000
Junior Member
 
Join Date: Oct 2003
Location: South France
Posts: 15
here it is

EDIT : i'm sorry about all the long post i've done before this but i'm not already very familiar with this board
Attached Files
File Type: zip id3_access.zip (9.6 KB, 146 views)
albator2000 is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > Winamp Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump