Ejemplo n.º 1
0
        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            string startFolder = @"C:\Users\ppras_000\Desktop\Creating Lasting Change";

            DirectoryInfo di = new DirectoryInfo(startFolder);

            foreach (var dir in di.GetDirectories())
            {
                foreach (var file in dir.GetFiles("*.mp3"))
                {
                    using (FileStream fs = new FileStream(file.FullName, FileMode.Open))
                    {
                        using (var mp3 = new Mp3Stream(fs, Mp3Permissions.ReadWrite))
                        {
                            Id3Tag tag = mp3.GetTag(Id3TagFamily.Version2x);
                            tag.Title.Value = file.Name.Substring(0, 2);
                            tag.Album.Value = dir.Name.Substring(0, 6);
                            mp3.WriteTag(tag);
                        }
                    }
                }
            }



            MessageBox.Show("Done");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// http://id3.codeplex.com/
        /// </summary>
        /// <param name="track"></param>
        public void getMP3Data(Track track)
        {
            var fs  = new FileStream(MediaFilename, FileMode.Open, FileAccess.Read);
            var mp3 = new Mp3Stream(fs);

            Id3Tag tag = mp3.GetTag(Id3TagFamily.FileStartTag);

            track.title  = tag.Title.Value;
            track.artist = tag.Artists.Value;

            fs.Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Retrieves either ID3V2 or Id3V1 tag
        /// </summary>
        /// <param name="mp3Stream">The MP3 stream.</param>
        /// <returns></returns>
        /// <exception cref="NullReferenceException"></exception>
        private Id3Tag GetTagFromStream(Mp3Stream mp3Stream)
        {
            Id3.Id3Tag tag = null;

            //Exit, we have no tags
            if (!mp3Stream.HasTags)
            {
                return(tag);
            }

            //Get the file start tag which is ID3v2
            tag = mp3Stream.GetTag(Id3TagFamily.FileStartTag);
            if (tag == null)
            {
                tag = mp3Stream.GetTag(Id3TagFamily.FileEndTag);

                if (tag == null)
                {
                    throw new NullReferenceException($"Couldn't parse tag for file");
                }
            }

            //Get the file start tag which is ID3v2
            else if (!tag.Year.IsAssigned)
            {
                var tagForYear = mp3Stream.GetTag(Id3TagFamily.FileEndTag);
                if (tagForYear != null)
                {
                    if (tagForYear.Year.IsAssigned)
                    {
                        var year = tagForYear.Year.AsDateTime.Value;
                        tag.Year.Value = Convert.ToString(year.Year);
                    }
                }
            }

            return(tag);
        }
Ejemplo n.º 4
0
        private string GetGenre(HttpPostedFileBase file)
        {
            var genre = string.Empty;
            using (var mp3 = new Mp3Stream(file.InputStream))
            {
                Id3Tag tag = mp3.GetTag(Id3TagFamily.FileStartTag);
                genre = tag.Genre;
                Console.WriteLine("Title: {0}", tag.Title.Value);
                Console.WriteLine("Artist: {0}", tag.Artists.Value);
                Console.WriteLine("Album: {0}", tag.Album.Value);

            }

            return genre;
        }
Ejemplo n.º 5
0
        public static TrackInfo GetTrackInfo(string mp3Path)
        {
            var trackInfo = new TrackInfo();

            using (var currentStream = new Mp3Stream(new FileStream(mp3Path, Open, Read)))
            {
                var id3Tag = currentStream.GetTag(Id3TagFamily.FileStartTag);
                trackInfo.Atrist    = id3Tag.Artists?.Value;
                trackInfo.Title     = id3Tag.Title?.Value;
                trackInfo.Bitrate   = currentStream.Audio.Bitrate;
                trackInfo.Duration  = currentStream.Audio.Duration;
                trackInfo.Frequency = currentStream.Audio.Frequency;
            }

            return(trackInfo);
        }
Ejemplo n.º 6
0
        public void ReadAlbumArt()
        {
            Id3Tag tag;

            using (FileStream stream = new FileStream(CurrentTrack.LocalPath, FileMode.Open, FileAccess.Read))
                using (Mp3Stream mp3 = new Mp3Stream(stream))
                    tag = mp3.GetTag(Id3TagFamily.FileStartTag);
            BitmapImage bitmapImage;

            try
            {
                PictureFrame image = tag.Pictures.FirstOrDefault();
                byte[]       bytes = image.PictureData;

                try
                {
                    bitmapImage = new BitmapImage();
                    using (MemoryStream memory = new MemoryStream(bytes))
                    {
                        bitmapImage.BeginInit();
                        bitmapImage.StreamSource = memory;
                        bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                        bitmapImage.EndInit();
                    }
                    ImageStretch = Stretch.UniformToFill;
                }
                catch (Exception)
                {
                    bitmapImage  = GetBitmapImage(new Uri("pack://application:,,,/Images/TakaneError.png", UriKind.Absolute));
                    ImageStretch = Stretch.None;
                }
            }
            catch (NullReferenceException)
            {
                bitmapImage  = GetBitmapImage(new Uri("pack://application:,,,/Images/TakaneNoImage.png", UriKind.Absolute));
                ImageStretch = Stretch.None;
            }
            AlbumArt = bitmapImage;
        }
Ejemplo n.º 7
0
        public void ReadAlbumArt()
        {
            Id3Tag tag;
            using (FileStream stream = new FileStream(CurrentTrack.LocalPath, FileMode.Open, FileAccess.Read))
            using (Mp3Stream mp3 = new Mp3Stream(stream))
                tag = mp3.GetTag(Id3TagFamily.FileStartTag);
            BitmapImage bitmapImage;
            try
            {
                PictureFrame image = tag.Pictures.FirstOrDefault();
                byte[] bytes = image.PictureData;

                try
                {
                    bitmapImage = new BitmapImage();
                    using (MemoryStream memory = new MemoryStream(bytes))
                    {
                        bitmapImage.BeginInit();
                        bitmapImage.StreamSource = memory;
                        bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
                        bitmapImage.EndInit();
                    }
                    ImageStretch = Stretch.UniformToFill;
                }
                catch (Exception)
                {
                    bitmapImage = GetBitmapImage(new Uri("pack://application:,,,/Images/TakaneError.png", UriKind.Absolute));
                    ImageStretch = Stretch.None;
                }
            }
            catch (NullReferenceException)
            {
                bitmapImage = GetBitmapImage(new Uri("pack://application:,,,/Images/TakaneNoImage.png", UriKind.Absolute));
                ImageStretch = Stretch.None;
            }
            AlbumArt = bitmapImage;
        }
Ejemplo n.º 8
0
 public void Tag()
 {
     if (this.AudioMedia != null)
     {
         try
         {
             using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
             {
                 var streamFile = store.OpenFile(Path.Combine(this.MediaSupportService.GetStorageDirectory(), this.AudioMedia.FilesystemId), FileMode.Open);
                 using (var streamMP3 = new Mp3Stream(streamFile))
                 {
                     Id3Tag tag = streamMP3.GetTag(Id3TagFamily.FileStartTag);
                     this.CurrentAlbum = tag.Album ?? string.Empty;
                     this.CurrentArtist = tag.Artists != null ? tag.Artists.Value ?? string.Empty : string.Empty;
                     this.SongTitle = tag.Title;
                 }
             }
         }
         catch (Exception e)
         {
             this.DialogViewService.MessageBoxOk(Main.Error, MusicList.TagError);
         }
     }
 }