0

I have the following code:

memoryStream is a stream that reads an aac file from an HLS stream. So it will be a packed AAC with ID3 tags in the beginning.

using var tagFile= TagLib.File.Create(new StreamFile(memoryStream), "audio/aac", ReadStyle.Average);
var id3v2tag= (TagLib.Id3v2.Tag)tagFile.GetTag(TagTypes.Id3v2);
var id3v1tag = (TagLib.Id3v1.Tag)tagFile.GetTag(TagTypes.Id3v1);

The tagFile.TagTypesOnDisk shows that its' of an Id3v2 tag. However, when I inspect id3v2tag, there aren't any properties set in there. Instead, it seems that id3v1tag is populated instead.

This is causing me issues as I want to be able to read a custom tag we have in there and the only way to do that is if we can use a TagLib.Id3v2.Tag type.

Is there something missing?

TagTypesOnDisk

SamIAm
  • 2,241
  • 6
  • 32
  • 51

1 Answers1

0

It turns out the aac file contains multiple ID3 tags. The first ID3 tag has the private frame of com.apple.streaming.transportStreamTimestamp. The second ID3 tag has the rest of the information that I'm looking for, such as title, artist, etc2.

Since there were multiple id3 tags in the aac file, tagFile.GetTag did not work. I had to do the following:

using var tag = TagLib.File.Create(new StreamFile(memoryStream), "audio/aac", ReadStyle.Average);
// Cast into a combined tag to retrieve the id3v2 variant
var nonContainerTag = (TagLib.CombinedTag)tag.Tag;
var id3v2Tag = (TagLib.Id3v2.Tag)nonContainerTag.Tags.FirstOrDefault(x => x.TagTypes == TagTypes.Id3v2 && x.Title == nonContainerTag.Title);
var customUserTextInformation = id3v2Tag.GetFrames<UserTextInformationFrame>();

customUserTextInformation would contain the custom ID3 metadata

SamIAm
  • 2,241
  • 6
  • 32
  • 51