/// <summary> /// Returns the list of all Vorbis Comments (tags for FLAC and OGG) related with the sound object. /// </summary> /// <returns>List of Vorbis Comments (Tags object)</returns> public Tags GetVorbisComments() { // Create the list of tags Tags tags = new Tags(); // Get the list of tags from FMOD List<FMOD.TAG> fmodTags = GetFMODTags(); // Check if the list is valid if (fmodTags != null) { // For each tag... foreach (FMOD.TAG fmodTag in fmodTags) { // Make sure it's a vorbis comment if (fmodTag.type == FMOD.TAGTYPE.VORBISCOMMENT) { // Detect the type of comment if (fmodTag.name.ToUpper() == "ARTIST") { tags.ArtistName = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "ALBUM") { tags.AlbumTitle = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TITLE") { tags.Title = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "GENRE") { tags.Genre = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TRACKNUMBER") { tags.TrackNumber = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "DATE") { } } } } return tags; }
/// <summary> /// Returns the list of all ID3 tag values related with the sound object. /// </summary> /// <returns>List of ID3 tag values</returns> public Tags GetID3Tags() { // Create object Tags tags = new Tags(); // Get the list of tags from FMOD List<FMOD.TAG> fmodTags = GetFMODTags(); // Check if the list is valid if (fmodTags != null) { // For each tag... foreach (FMOD.TAG fmodTag in fmodTags) { // Make sure it's an ID3 tag if(fmodTag.type == FMOD.TAGTYPE.ID3V1 || fmodTag.type == FMOD.TAGTYPE.ID3V2) { if (fmodTag.name.ToUpper() == "ARTIST") { tags.ArtistName = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "ALBUM") { tags.AlbumTitle = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TITLE") { tags.Title = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "YEAR") { tags.Year = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TRACK") { tags.TrackNumber = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "GENRE") { tags.Genre = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TIT2") { tags.Tit2 = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TALB") { tags.Talb = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TSRC") { tags.Tsrc = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TCON") { tags.Tcon = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TDRC") { tags.Tdrc = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TRCK") { tags.Trck = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TPE1") { tags.Tpe1 = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "TXXX") { tags.Txxx = Marshal.PtrToStringAnsi(fmodTag.data); } else if (fmodTag.name == "APIC") { try { // Load binary data and transform to bitmap byte[] byteAryPic = new byte[(int)fmodTag.datalen]; Marshal.Copy(fmodTag.data, byteAryPic, 0, (int)fmodTag.datalen); //ID3PictureFrame frame = new ID3PictureFrame(byteAryPic); //MemoryStream memStream = new MemoryStream(); //BinaryWriter binWriter = new BinaryWriter(memStream); ////Write the data //for (int i = 13; i < byteAryPic.Length; i++) //{ // binWriter.Write(byteAryPic[i]); //} //tags.Picture = new Bitmap(memStream); //binWriter.Close(); //memStream.Close(); } catch (Exception ex) { throw ex; } } } } } return tags; }
/// <summary> /// Gets the tags of the song for every sound format. /// Uses TagLib# by default. If TagLib# fails, the method uses FMOD's tagging system. /// </summary> /// <returns>List of tags</returns> public Tags GetTags() { // Create variables Tags tags = new Tags(); // Try to get tags from TagLib try { // Get tags if (FilePath.ToUpper().Contains("MP3")) { TagLib.Mpeg.AudioFile a = new TagLib.Mpeg.AudioFile(FilePath); foreach(TagLib.ICodec codec in a.Properties.Codecs) { TagLib.Mpeg.AudioHeader header = (TagLib.Mpeg.AudioHeader)codec; //if (header == null) //{ // break; //} } tags = GetID3Tags(); //TagLib.Mpeg.VBRIHeader b = new TagLib.Mpeg.VBRIHeader(); //TagLib.Mpeg.AudioHeader c = new TagLib.Mpeg.AudioHeader(); } TagLib.File songInfo = TagLib.File.Create(FilePath); // Get album artist if available if (songInfo.Tag.AlbumArtists.Length > 0) { tags.ArtistName = songInfo.Tag.AlbumArtists[0]; } // But by default we are taking the artists else if (songInfo.Tag.Artists.Length > 0) { tags.ArtistName = songInfo.Tag.Artists[0]; } // Get other tags if (!string.IsNullOrEmpty(songInfo.Tag.Album)) { tags.AlbumTitle = songInfo.Tag.Album; } // Set other properties tags.Title = songInfo.Tag.Title; tags.TrackNumber = songInfo.Tag.Track.ToString(); tags.DiscNumber = songInfo.Tag.Disc.ToString(); tags.Year = songInfo.Tag.Year.ToString(); tags.Genre = string.Empty; return tags; } catch (Exception ex) { // Continue with FMOD instead } // Determine sound format string extension = Path.GetExtension(FilePath).ToUpper(); if(extension.Contains("FLAC") || extension.Contains("OGG")) { // Get Vorbis Comments tags = GetVorbisComments(); } else if (extension.Contains("MP3")) { // Get ID3 tags tags = GetID3Tags(); } return tags; }