Search Tools Links Login

MP3 ID3v1 Tag Read/Write Class


Use this class to read and/or write to the ID3 tag of an MP3.

Original Author: Kevin Roth

Inputs

Must pass full file paths to the gettag and writetag subs

Code

Public ValidTag As String
Public Title As String
Public Artist As String
Public Year As String
Public Album As String
Public Comment As String
Public Genre As Byte
Private Type ID3v1
  ValidTag As String * 3
  Title As String * 30
  Artist As String * 30
  Album As String * 30
  Year As String * 4
  Comment As String * 30
  Genre As Byte
End Type
  
Public Sub getTag(MP3 As String)
  Dim ID3 As ID3v1
  Open MP3 For Binary As #1
  Get #1, FileLen(MP3) - 127, ID3
  Close #1
  
  With ID3
   ValidTag = .ValidTag
   Title = .Title
   Artist = .Artist
   Album = .Album
   Comment = .Comment
   Year = .Year
   Genre = .Genre
  End With
End Sub
Public Sub writeTag(MP3 As String)
  Dim ID3 As ID3v1
  
  With ID3
   .ValidTag = "TAG"
   .Title = Title
   .Artist = Artist
   .Album = Album
   .Comment = Comment
   .Year = Year
   .Genre = Genre
  End With
  On Error GoTo ErrMsg:
  Open MP3 For Binary As 1
  If ID3.ValidTag <> "TAG" Then
    Seek 1, LOF(1) + 1
  Else
    Seek 1, LOF(1) - 127
  End If
  Put 1, FileLen(MP3) - 127, ID3
  Close 1
  Exit Sub
ErrMsg:
  MsgBox ("File '" & MP3 & "' is marked as read-only or the file is in use." & vbCr & "Please correct and try again.")
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 104 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.