Archive for 四月 11th, 2009

VB6实现MP3标签读取~自己修改

四月 11, 2009 - 5:25 下午 评论关闭

没管它到底第几字符到第几字符是什么内容,用的While一个字一个字读的按顺序来的,从理论上说只要不写满了就不会出错。

这是用来编写多媒体管理系统中英语课本光盘MP3的模块,上网找的那个读出来的东西云山雾绕,跟XXX似的,自己改了改

放在一模块里即可。

VB6 Code

'声明一个自定义类型
Public Type mp3Tag
Artist As String 'Artist 存储歌手信息
Album As String 'Album 存储唱片专辑信息
Title As String 'Title 存储标题信息
End Type

Public Function GetMp3Tag(FName As String) As mp3Tag

Dim a(5) As String, i As Integer, FileNum As Integer, cg As Boolean
FileNum = FreeFile '得到一个自由的文件号
If FName = "" Then Exit Function
If Dir(FName) = "" Then Exit Function
cg = False
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
i = 0
While Not EOF(FileNum)
strInput = Space(1)
Get FileNum, , strInput
If Asc(strInput) <> 0 Then
cg = False
a(i) = a(i) & strInput
Else
If Not cg Then i = i + 1
cg = True
End If
Wend
Done:
GetMp3Tag.Title = a(0)
GetMp3Tag.Artist = a(1)
GetMp3Tag.Album = a(2)
Close FileNum
End Function

2010,PokeTB.