Пример #1
0
        /// <summary>
        /// Creates new instance of Song and maps all IDv info about it to the class.
        /// </summary>
        public static Song New(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(nameof(filePath));
            }

            var reader = File.Open(filePath, FileMode.Open);

            var streamFileAbstraction = new StreamFileAbstraction(filePath, reader, reader);

            var tagFile = TagLib.File.Create(streamFileAbstraction);

            reader.Close();

            return(new Song
            {
                Name = System.IO.Path.GetFileNameWithoutExtension(filePath),
                Path = filePath,
                Artist = tagFile.Tag.FirstAlbumArtist,
                Album = tagFile.Tag.Album,
                Title = tagFile.Tag.Title,
                Year = tagFile.Tag.Year,
                Lenght = tagFile.Length
            });
        }
Пример #2
0
        public static TagLib.File ReadTag(MemoryStream fs, string path)
        {
            var fsa = new StreamFileAbstraction(path, fs, fs);

            try
            {
                TagLib.File file = TagLib.File.Create(fsa);
                return(file);
            }
            catch (CorruptFileException cex)
            {
                Console.WriteLine(cex);
                return(null);
            }
        }
Пример #3
0
        public static void Main(string[] args)
        {
            const string path = @"clip.mp3";

            using (var fileStream = new FileStream(path, FileMode.Open))
            {
                var fileStreamAbstraction = new StreamFileAbstraction(path,
                                                                      fileStream, fileStream);
                var tagFile = TagLib.File.Create(fileStreamAbstraction);
                var tags    = tagFile.GetTag(TagTypes.Id3v2);
                Console.WriteLine($"Title\t\t{tags.Title}");
                Console.WriteLine($"Artist\t\t{tags.JoinedAlbumArtists}");
                Console.WriteLine($"Comment\t\t{tags.Comment}");
                Console.ReadLine();
            }
        }