Results 1 to 2 of 2

Thread: [RESOLVED] taglib-sharp - Read custom tags from MP3 files

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2017
    Posts
    33

    Resolved [RESOLVED] taglib-sharp - Read custom tags from MP3 files

    I've been using taglib-sharp for many years on our Upload script for our website.
    Today, I found out how to access the Duration from it, so now I am using taglib-sharp for all my tags.
    (For those interested in the Duration)


    Code:
    Dim strDuration = mp31.Properties.Duration  
    Dim strDurations As String = strDuration.ToString("mm\:ss")

    The MP3 Editor I use MP3Tag
    Allows you to create Custom Tags.
    An example of a tag is.
    Producer Eddie Kramer

    What I need is to have taglib-sharp read these Custom Tags.
    From what I have read, it seems that it is possible.


    I found this here on SO. adding custom tag using the taglib-sharp library
    And this is what I tried. (After converting it over from C# to VB)
    Code:
    Imports TagLib.Id3v2
    
    Dim f As File = File.Create(Server.MapPath("/Files/Do_You_Love_Me.mp3"))
    Dim t As TagLib.Id3v2.Tag = CType(f.GetTag(TagTypes.Id3v2), TagLib.Id3v2.Tag)
    Dim p As PrivateFrame = PrivateFrame.[Get](t, "PRODUCER", False)
    Dim strProducer As String = Encoding.Unicode.GetString(p.PrivateData.Data)
    Also tried this as well, but with the same error as shown below.
    Code:
        Dim tfile = f
        Dim custom = CType(tfile.GetTag(TagLib.TagTypes.Xiph), TagLib.Ogg.XiphComment)
        Dim myfields As String() = custom.GetField("PRODUCER")
    When I run it, I get this error.

    System.NullReferenceException: 'Object reference not set to an instance of an object.'
    p was Nothing.
    So, it is not reading the custom tag.
    It seems it is not being initialized, but how?

    I installed VS Code and then installed the Hex Editor from Microsoft.
    I loaded the MP3 file into Code and invoked the Hext Editor. The tag "PRODUCER" and its value are clearly visible.
    So, the tag is present but is just not being read through the TagLib-sharp code.

    Viewing the code from the ID3v2Library.pas (Delphi Component File)
    Code:
    ConvertString2FrameID('TXXX', Frames[FrameIndex].ID);
    I see where the FRAME ID matches what I am seeing in the HEX Editor for the MP3 file.
    All the CUSTOM TAGS are listed with the FRAMEID of **TXXX**.

    So, the code is erroring out on these lines for both codes.

    Code:
    Dim p As PrivateFrame = PrivateFrame.[Get](t, "PRODUCER", False) ' This one
    Dim myfields As String() = custom.GetField("PRODUCER") ' And then this one.
    What needs to be initialized to make this work is to read the custom metadata tags from the mp3 files.

    Thanks.
    Wayne

  2. #2

    Thread Starter
    Member
    Join Date
    Feb 2017
    Posts
    33

    Re: [RESOLVED] taglib-sharp - Read custom tags from MP3 files

    I am no longer using this code, I have switched over to a code that is constantly being updated.
    NReco.VideoInfo

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width