我正在尝试获取属性中的MP3标题。例如,文件名是“iasn_E_052”,但歌曲名称是“Guard Your Heart”。获取文件名很简单,但歌曲标题是我不知道如何。我正在使用vb.net visual studio 2013。
答案 0 :(得分:0)
标题或艺术家等元数据在文件中存储为ID3。 您需要按字节读取文件并将特定字节转换为字符串 例如,ID3v1标记存储在文件的最后128个字节中。前三个字节是" TAG"接下来的30个字节是标题。
Option Strict On
Imports System.IO
Class MP3Tags
Sub GetTitle(filename As String)
Dim buffer(30) As Byte
Dim reader As New FileStream(filename, FileMode.Open, FileAccess.Read)
Dim length = reader.Length
If (length > 128) Then
reader.Seek(-128, SeekOrigin.End)
reader.Read(buffer, 0, 3)
Dim tag As String = System.Text.Encoding.ASCII.GetChars(buffer, 0, 3)
If (tag = "TAG") Then
reader.Read(buffer, 0, 30)
Dim title As String = System.Text.Encoding.ASCII.GetChars(buffer, 0, 30)
Console.WriteLine("Title = " + title)
Else
Console.WriteLine("File doesn't contain ID3v1 tags")
End If
Else
Console.WriteLine("File is too short to have tags")
End If
End Sub
End Class
(基于此class)