我已经读取了mp3文件的后128字节,但只有一部分文件按照网上所说的方法正确的读出如:歌手名,歌曲名,专辑,年份等信息,但有一部分mp3无法读取,读取到的是空值,因为我看到Win7操作系统都可以正确读取出这些我读取不到的歌曲的附加信息。
除了最后128字节是否还有其它方法或者是我的方法有问题吗?这可是从微软的MSDN上下载的代码呀?
以下是我代码:
Option Explicit Public Type ID3Tag Header As String * 3 SongTitle As String * 30 Artist As String * 30 Album As String * 30 Year As String * 4 Comment As String * 30 Genre As Byte End Type Private Function GetNullTerminateString(ByVal str As String) As String Dim pos As Integer pos = InStr(str, Chr(0)) If pos < 1 Then GetNullTerminateString = str Exit Function End If GetNullTerminateString = Left(str, pos - 1) End Function Public Function GetID3Tag(ByVal strFileName As String) As clsSongInfo On Error GoTo GetID3TagError Dim TempTag As ID3Tag Dim FileNum As Long If Dir(strFileName) = "" Then Exit Function End If FileNum = FreeFile Open strFileName For Binary As FileNum Get FileNum, LOF(1) - 127, TempTag Close FileNum If TempTag.Header = "TAG" Then Dim tag As New clsSongInfo tag.Header = Trim(GetNullTerminateString(TempTag.Header)) tag.SongTitle = Trim(GetNullTerminateString(TempTag.SongTitle)) tag.Artist = Trim(GetNullTerminateString(TempTag.Artist)) tag.Album = Trim(GetNullTerminateString(TempTag.Album)) tag.Year = Trim(GetNullTerminateString(TempTag.Year)) tag.Comment = Trim(GetNullTerminateString(TempTag.Comment)) Set GetID3Tag = tag End If Exit Function GetID3TagError: Close FileNum Set GetID3Tag = Nothing End Function
最后128字节是ID3V1的信息,容量有限,可以存储的数据很少。现在大部分的信息是ID3V2格式,存在mp3的头部,你解析的只是Id3v1信息,自然有的数据获取不到。
多谢指点,我搜了一圈,连这种常识性问题都不懂,太悲剧了。