VB:读取MP3的Tag(对网上流行版本改进)

网上有一段关于VB读取MP3Tag的代码,但不支持中文。这里我对这个代码进行改进。

这是我改进后的代码:

Public Type Mp3tag
        Artist   As String  'Artist  
存储歌手信息
        Album    As String  'Album    存储唱片专辑信息
        Title    As String 
'Title    存储标题信息
        sYear    As String  'Year     存储年代信息
        Comments As String 
'Comments 存储备注信息
        Genre    As Integer
'Genre    存储音乐风格序列
End Type

Public Function GetMp3Tag(FName As String) As Mp3tag
    Dim Artist   As String
    Dim Album   As String
    Dim Title   As String
    Dim Year   As String
    Dim Comments   As String
    Dim Genre   As Integer
    If FName = "" Then Exit Function
    If Dir(FName) = "" Then Exit Function
    Dim FileNum   As Integer
    FileNum = FreeFile '
得到一个自由的文件号
    Dim strInput() As Byte
   
Open FName For Binary Access Read As FileNum '以二进制形式打开文件
    If LOF(FileNum) < 128 Then
       
Close FileNum
       
Exit Function
    End If
   
Seek FileNum, LOF(FileNum) - 127 '把文件指针移动到MP3信息处
   
ReDim strInput(2)
    Get FileNum, , strInput
    If StrConv(strInput, vbUnicode) <> "TAG" Then
'如果没有发现信息标识,就关闭文件
       
Close FileNum
       
GoTo Done
    End If
    On Error Resume Next
    ReDim strInput(29)
    Get FileNum, , strInput
    Title = StrConv(strInput, vbUnicode)
    Title = Left$(Title, InStr(1, Title, vbNullChar) - 1)
    Get FileNum, , strInput
    Artist = StrConv(strInput, vbUnicode)
    Artist = Left$(Artist, InStr(1, Artist, vbNullChar) - 1)
    Get FileNum, , strInput
    Album = StrConv(strInput, vbUnicode)
    Album = Left$(Album, InStr(1, Album, vbNullChar) - 1)
    ReDim strInput(3)
    Get FileNum, , strInput
    sYear = StrConv(strInput, vbUnicode)
    sYear = Left$(Year, InStr(1, Year, vbNullChar) - 1)
   
ReDim strInput(29)
    Get FileNum, , strInput
    Comments = StrConv(strInput, vbUnicode)
    Comments = Left$(Comments, InStr(1, Comments, vbNullChar) - 1)
   
ReDim strInput(0)
    Get FileNum, , strInput
    Genre =
Asc(strInput)
Done:
    GetMp3Tag.Title = Title
    GetMp3Tag.Artist = Artist
    GetMp3Tag.Album = Album
    GetMp3Tag.sYear = sYear
    GetMp3Tag.Comments = Comments
    If Genre < 0 Or Genre > 254 Then Genre = 12
    GetMp3Tag.Genre = CInt(Genre)
   
Close FileNum
End Function

阅读更多

没有更多推荐了,返回首页