private TagLib.File OpenAudioFile(string path, string ext) // Opens a proper file format via TagLib# and gets a file hadler object
        {
            TagLib.File audioFile = null;

            switch (ext) // Opening correct file type with TagLib#
            {
            case "MP3":
                audioFile = new TagLib.Mpeg.AudioFile(path, TagLib.ReadStyle.Average);
                break;

            case "FLAC":
                audioFile = new TagLib.Flac.File(path, TagLib.ReadStyle.Average);
                break;

            case "APE":     // Generally not supported yet
                audioFile = new TagLib.Ape.File(path, TagLib.ReadStyle.Average);
                break;

            case "AAC":     // Generally not supported yet
                audioFile = new TagLib.Aac.File(path, TagLib.ReadStyle.Average);
                break;

            case "AIFF":     // Generally not supported yet
                audioFile = new TagLib.Aiff.File(path, TagLib.ReadStyle.Average);
                break;

            default:
                audioFile = TagLib.File.Create(path);
                break;
            }

            return(audioFile);
        }
Exemple #2
0
 public Audio(string filePath) : base(filePath)
 {
     if (this.Extension.ToLower() == ".mp3")
     {
         TagLib.Mpeg.AudioFile audioFile = new TagLib.Mpeg.AudioFile(filePath);
         _artist          = audioFile.Tag.FirstAlbumArtist;
         _album           = audioFile.Tag.Album;
         _genre           = audioFile.Tag.FirstGenre;
         _lengthInSeconds = (int)Math.Round(audioFile.Properties.Duration.TotalSeconds);
     }
     else if (this.Extension.ToLower() == ".wav")
     {
         TagLib.Riff.File audioFile = new TagLib.Riff.File(filePath);
         _artist          = audioFile.Tag.FirstAlbumArtist;
         _album           = audioFile.Tag.Album;
         _genre           = audioFile.Tag.FirstGenre;
         _lengthInSeconds = (int)Math.Round(audioFile.Properties.Duration.TotalSeconds);
     }
     else if (this.Extension.ToLower() == ".aiff")
     {
         TagLib.Aiff.File audioFile = new TagLib.Aiff.File(filePath);
         _artist          = audioFile.Tag.FirstAlbumArtist;
         _album           = audioFile.Tag.Album;
         _genre           = audioFile.Tag.FirstGenre;
         _lengthInSeconds = (int)Math.Round(audioFile.Properties.Duration.TotalSeconds);
     }
     else if (this.Extension.ToLower() == ".flac")
     {
         TagLib.Flac.File audioFile = new TagLib.Flac.File(filePath);
         _artist          = audioFile.Tag.FirstAlbumArtist;
         _album           = audioFile.Tag.Album;
         _genre           = audioFile.Tag.FirstGenre;
         _lengthInSeconds = (int)Math.Round(audioFile.Properties.Duration.TotalSeconds);
     }
     else if (this.Extension.ToLower() == ".aa" || this.Extension.ToLower() == ".aax")
     {
         TagLib.Audible.File audioFile = new TagLib.Audible.File(filePath);
         _artist          = audioFile.Tag.FirstAlbumArtist;
         _album           = audioFile.Tag.Album;
         _genre           = audioFile.Tag.FirstGenre;
         _lengthInSeconds = (int)Math.Round(audioFile.Properties.Duration.TotalSeconds);
     }
 }