vb.net中读取mp3标签信息

发布于 2024-11-15 01:34:17 字数 563 浏览 7 评论 0原文

我正在VB.NET 2005中做一个项目,其中我必须提取mp3文件的标签信息。为此,我在此页面中使用了代码。但问题是当其中一个标签为空时,它不会返回任何值。

例如,使用这个我可以像这样检索专辑信息,

    Dim album As String = ""
    album = objMP3V1.Frame(MP3ID3v1.FrameTypes.Album)

但我不知道如何检查专辑变量是否为空,我检查了专辑变量

    If (album = "") Then
        MsgBox("true")
    ElseIf (album Is Nothing) Then
        MsgBox("true")
    ElseIf (album Is DBNull.Value) Then
        MsgBox("true")
    End If

但没有成功,有人可以帮助我。

I'm doing a project in VB.NET 2005, in which I have to extract the tag information of mp3 files. For that purpose I have used code in this page. But the issue is when one of the tag is empty, it didn't return any values.

For example, using this i can retrieve album information like this,

    Dim album As String = ""
    album = objMP3V1.Frame(MP3ID3v1.FrameTypes.Album)

But I didn't know how to check the album variable is empty or not, I checked album variable

    If (album = "") Then
        MsgBox("true")
    ElseIf (album Is Nothing) Then
        MsgBox("true")
    ElseIf (album Is DBNull.Value) Then
        MsgBox("true")
    End If

but no success, can somebody help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

变身佩奇 2024-11-22 01:34:17

ID3v1 标签存储在文件的最后 128 个字节中。前三个字节是“TAG”,表示文件存储标签。所以首先检查文件是否有标签,然后读取它们。

我不懂VB,但我认为在阅读框架之前,您应该首先:

  1. 打开文件 Dim objMP3V1 As New MP3ID3v1("file_path")
  2. 测试,通过测试文件中是否有 ID3v1 标签如果 objMP3V1.TagExists 标志为 true
  3. 然后读取字段/帧。

编辑

链接中的代码显示,

FileGet(intFile, strTag, lngLOF - 127, True)
        If (strTag.ToUpper <> "TAG") Then

            ' No ID3v1 tag found

            mblnTagExists = False
            mobjFrame(0) = ""
            mobjFrame(1) = ""
            mobjFrame(2) = ""
            mobjFrame(3) = ""
            mobjFrame(4) = ""
            mobjFrame(5) = ""
            mobjFrame(6) = ""

        Else

            ' ID3v1 tag found

            mblnTagExists = True

            ' Read all frames from the file

            FileGet(intFile, strTitle)
            FileGet(intFile, strArtist)
            FileGet(intFile, strAlbum)
            FileGet(intFile, strYear)
            FileGet(intFile, strComment)
            FileGet(intFile, bytDummy)
            FileGet(intFile, bytTrack)
            FileGet(intFile, bytGenre)

            ' Assign the frame content to the properties

            mobjFrame(0) = strTitle
            mobjFrame(1) = strArtist
            mobjFrame(2) = strAlbum
            mobjFrame(3) = strYear
            mobjFrame(4) = bytTrack
            mobjFrame(5) = strComment
            mobjFrame(6) = bytGenre

        End If
    End If

因此,如果标签不存在,则应将 "" 指定为字符串。

ID3v1字段是固定长度的,因此如果album字段中没有字符串,那么它应该包含一个num字符串,即该字段的第一个位置将包含一个空字符' \0',因此它将返回一个空字符串""
我会告诉您在带有 ID3v1 标签的示例音乐文件上检查这一点。 (您甚至可以创建一个 ID3v1 格式的文本文件并进行测试)。

The ID3v1 tag is stored in the last 128 bytes of the file. The first three bytes is "TAG" telling that the file stores the tag. So first check if the file has a tag, Then read them.

I do not know VB but i think before reading the frame, you should first:

  1. Open the file Dim objMP3V1 As New MP3ID3v1("file_path")
  2. Test, if the file has an ID3v1 tag in it by testing if objMP3V1.TagExists flag is true
  3. Then read the fields/frames.

EDIT

The code in the link says

FileGet(intFile, strTag, lngLOF - 127, True)
        If (strTag.ToUpper <> "TAG") Then

            ' No ID3v1 tag found

            mblnTagExists = False
            mobjFrame(0) = ""
            mobjFrame(1) = ""
            mobjFrame(2) = ""
            mobjFrame(3) = ""
            mobjFrame(4) = ""
            mobjFrame(5) = ""
            mobjFrame(6) = ""

        Else

            ' ID3v1 tag found

            mblnTagExists = True

            ' Read all frames from the file

            FileGet(intFile, strTitle)
            FileGet(intFile, strArtist)
            FileGet(intFile, strAlbum)
            FileGet(intFile, strYear)
            FileGet(intFile, strComment)
            FileGet(intFile, bytDummy)
            FileGet(intFile, bytTrack)
            FileGet(intFile, bytGenre)

            ' Assign the frame content to the properties

            mobjFrame(0) = strTitle
            mobjFrame(1) = strArtist
            mobjFrame(2) = strAlbum
            mobjFrame(3) = strYear
            mobjFrame(4) = bytTrack
            mobjFrame(5) = strComment
            mobjFrame(6) = bytGenre

        End If
    End If

So, if the tag is not present then it should have "" assigned as the string.

ID3v1 fields are of fixed length, so if there is no string in the album field then it should contain a num string, that is, the first location of the field will contain a null character '\0', therefore it will return a null string "".
I would tell you to check the this on a sample music file with ID3v1 tags. (You can even create a text file formatted with ID3v1 and test it).

江挽川 2024-11-22 01:34:17

我使用正则表达式来解决这个问题。感谢您的帮助...

Imports System.Text.RegularExpressions
dim RegEx As New RegularExpressions.Regex("^[a-zA-Z0-9]+$")
dim Match As Match
dim film as string
film = song.Frame(MP3ID3v1.FrameTypes.Album)
Match = RegEx.Match(film)
film1 = IIf((Match.Success), film.ToString, "")  

如果您正在寻找更专业的标签编辑器,这里有链接

I've used regular expression to solve this issue. Thanks for all your help...

Imports System.Text.RegularExpressions
dim RegEx As New RegularExpressions.Regex("^[a-zA-Z0-9]+$")
dim Match As Match
dim film as string
film = song.Frame(MP3ID3v1.FrameTypes.Album)
Match = RegEx.Match(film)
film1 = IIf((Match.Success), film.ToString, "")  

If you looking for more professional tag editior Here's a link!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文