/// <summary> /// Retrieve a tag with an arbitrary name. /// Returns an empty tag if the value isn't found or if no Xiph tags are present. /// </summary> /// <param name="TagName"> /// A <see cref="System.String"/> containing the name of the tag to find /// </param> /// <returns> /// An <see cref="OggTag"/> containing the returned tag /// </returns> public OggTag GetTag(string TagName) { if (TagName.Length <= 0) { return(OggUtilities.GetEmptyTag()); } // Save some processing time and just exit if we haven't been given a tag name // Based on tasty examples @ "Accessing Hidden Gems": http://developer.novell.com/wiki/index.php/TagLib_Sharp:_Examples TagLib.Ogg.XiphComment XC = (TagLib.Ogg.XiphComment)m_TagLibFile.GetTag(TagTypes.Xiph); if (XC != null) { string[] TagValue = XC.GetField(TagName); if (TagValue.Length == 0) { // Tag doesn't exist, return empty return(OggUtilities.GetEmptyTag()); } else { OggTag tmpTag; tmpTag.Name = TagName; tmpTag.IsArray = (TagValue.Length > 1); tmpTag.IsEmpty = false; tmpTag.Values = TagValue; tmpTag.Value = TagValue[0]; return(tmpTag); } } else { // No valid Xiph tags found return(OggUtilities.GetEmptyTag()); } }
/// <summary> /// Retrieve an array of all tag values /// Returns a zero-length array if no Xiph tags are found /// </summary> /// <returns> /// An <see cref="OggTag[]"/> containing the returned values /// </returns> public OggTag[] GetTags() { TagLib.Ogg.XiphComment XC = (TagLib.Ogg.XiphComment)m_TagLibFile.GetTag(TagTypes.Xiph); if (XC != null) { if (XC.FieldCount > 0) { OggTag[] tmpOggTag = new OggTag[XC.FieldCount]; int Index = 0; foreach (string FieldName in XC) { string[] TagValue = XC.GetField(FieldName); if (TagValue.Length == 0) { tmpOggTag[Index] = OggUtilities.GetEmptyTag(); // This should never happen, but I bet if I don't check it it will! } else { // Populate this tag tmpOggTag[Index].Name = FieldName; tmpOggTag[Index].IsArray = (TagValue.Length > 1); tmpOggTag[Index].IsEmpty = false; tmpOggTag[Index].Values = TagValue; tmpOggTag[Index].Value = TagValue[0]; } ++Index; // Increment the index so we know which OggTag we're molesting } // Done! Return the heap of tags return(tmpOggTag); } else { // Xiph tags contain no items return(new OggTag[0]); } } else { // No valid Xiph tags found return(new OggTag[0]); } }