[摘要]为了保护音乐者的版权,在MP3文件中有一段特意存储版权说明的信息,众多的MP3播放器软件都提供了修改和读取MP3文件中隐藏信息的功能,那么这些信息到底存储在哪里呢?如何得到这些信息呢?本文将为大家提...
为了保护音乐者的版权,在MP3文件中有一段特意存储版权说明的信息,众多的MP3播放器软件都提供了修改和读取MP3文件中隐藏信息的功能,那么这些信息到底存储在哪里呢?如何得到这些信息呢?本文将为大家提供得到MP3信息的模块。
首先,定义一个公共类型Mp3tag如下:
Public Type Mp3tag
Artist As String ’Artist 存储歌手信息
Album As String ’Album 存储唱片专辑信息
Title As String ’Title 存储标题信息
Year As String ’Year 存储年代信息
Comments As String ’Comments 存储备注信息
Genre As Integer ’Genre 存储音乐风格序列
End Type
然后,定义一个获取MP3信息的函数,它将返回这些信息,代码如下:
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 String
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信息处
strInput = Space(3)
Get FileNum, , strInput
If strInput <> "TAG" Then ’如果没有发现信息标识,就关闭文件
Close FileNum
GoTo Done:
End If
strInput = Space(30)
Get FileNum, , strInput
Title = Trim(strInput)
strInput = Space(30)
Get FileNum, , strInput
Artist = Trim(strInput)
strInput = Space(30)
Get FileNum, , strInput
Album = Trim(strInput)
strInput = Space(4)
Get FileNum, , strInput
Year = Trim(strInput)
strInput = Space(30)
Get FileNum, , strInput
Comments = Trim(strInput)
strInput = Space(1)
Get FileNum, , strInput
Genre = Asc(strInput)
Done:
GetMp3Tag.Title = Title
GetMp3Tag.Artist = Artist
GetMp3Tag.Album = Album
GetMp3Tag.Year = Year
GetMp3Tag.Year = Comments
If Genre < 0 Or Genre > 254 Then Genre = 12
GetMp3Tag.Genre = CInt(Genre)
Close FileNum
End Function
注意:MP3文件对音乐的风格进行了限制,共254种。Genre返回的只是MP3风格的序列号,具体还需要定位,在这里我把所有类型以常数形式列出,每个类型之间用"
关键词:得到MP3中隐藏的信息