使用Visual Basic解释MP3的Tag信息
编号:QA003316
建立日期: 2000年9月8日 最后修改日期:2000年9月8日
所属类别:
文章:
李海译自《IVBTips》
Windows Media Player提供了Visual Basic程序方便快捷的播放MP3的能力。一旦你拥有一个MP3文件,你可能想知道如何读取一首歌的信息,象歌曲的标题和艺术家的名字。如果MP3文件使用最流行的tag加密方法ID3,则你很幸运。这个标准保存Tag信息在文件的最后128个字节中(Tag:3, 标题:30, 艺术家:30,纪念册:30, 年:4, 注释:30, 流派:1)
为了读取信息,先打开MP3文件,然后读最后128字节。按照ID3,如果文件中包括信息,前三个字节应该存储字符TAG。如果确实包含Tag信息,保存最后128字节进一个定制变量。这之后,遍历MP3文件,提取你要的信息。下面的过程演示了提取的代码,同时建立了几个后面要用到的重要变量。
Option Explicit
Private Type TagInfo
Tag As String * 3
Songname As String * 30
artist As String * 30
album As String * 30
year As String * 4
comment As String * 30
genre As String * 1
End Type
Dim FileName As String
Dim CurrentTag As TagInfo
Private Sub Form1_Load()
Dim temp As String
On Error Resume Next
FileName = App.Path & "\myMP3.mp3"
Open FileName For Binary As #1
With CurrentTag
Get #1, FileLen(FileName) - 127, .Tag
If Not .Tag = "TAG" Then
label8.Caption = "No tag"
Close #1
Exit Sub
End If
Get #1, , .Songname
Get #1, , .artist
Get #1, , .album
Get #1, , .year
Get #1, , .comment
Get #1, , .genre
Close #1
txtTitle = RTrim(.Songname)
txtArtist = RTrim(.artist)
txtAlbum = RTrim(.album)
txtYear = RTrim(.year)
txtComment = RTrim(.comment)
Temp = RTrim(.genre)
txtGenreCode = Asc(Temp)
Combo1.ListIndex = CInt(txtGenreCode) - 1
End With
End Sub
注意代码中处理流派字符有点不同。这是因为ID3保存数据为一个单独的ASCII字符。为了匹配实际对应的描述(包括在一个组合框中),这个过程转换ASCII字符为一个数字,然后在组合框中查找。
文章来源:IVBTips。
| |
|
|
| |
|
|