Ejemplo n.º 1
0
        public Picture(IAttachedPicture attachedPicture)
        {
            if (attachedPicture == null)
            {
                throw new ArgumentNullException("attachedPicture");
            }

            _attachedPicture = attachedPicture;

            Description = attachedPicture.Description;
            PictureType = attachedPicture.PictureType;

            byte[] pictureData = attachedPicture.PictureData;
            PictureBytes = pictureData;
            if (pictureData != null)
            {
                try
                {
                    MemoryStream memoryStream = new MemoryStream(pictureData);
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = memoryStream;
                    bitmapImage.EndInit();

                    ImageSource = bitmapImage;
                }
                catch (NotSupportedException)
                {
                }
            }
        }
Ejemplo n.º 2
0
        public Picture(IAttachedPicture attachedPicture)
        {
            if (attachedPicture == null)
                throw new ArgumentNullException("attachedPicture");

            _attachedPicture = attachedPicture;

            Description = attachedPicture.Description;
            PictureType = attachedPicture.PictureType;

            byte[] pictureData = attachedPicture.PictureData;
            PictureBytes = pictureData;
            if (pictureData != null)
            {
                try
                {
                    MemoryStream memoryStream = new MemoryStream(pictureData);
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = memoryStream;
                    bitmapImage.EndInit();

                    ImageSource = bitmapImage;
                }
                catch (NotSupportedException)
                {
                }
            }
        }
Ejemplo n.º 3
0
        private void cmbImageType_SelectedIndexChanged(object sender, EventArgs e)
        {
            IAttachedPicture attachedPicture = GetCurrentPictureFrame();

            if (attachedPicture != null)
            {
                attachedPicture.PictureType = PictureTypeHelper.GetPictureTypeFromString(cmbImageType.Text);
            }
        }
Ejemplo n.º 4
0
        private void txtImageDescription_Validated(object sender, EventArgs e)
        {
            IAttachedPicture attachedPicture = GetCurrentPictureFrame();

            if (attachedPicture != null)
            {
                attachedPicture.Description = txtImageDescription.Text;
            }
        }
Ejemplo n.º 5
0
        private void OnSaveFile()
        {
            _id3v2.Artist            = Artist;
            _id3v2.Title             = Title;
            _id3v2.Album             = Album;
            _id3v2.Genre             = Genre;
            _id3v2.Year              = Year;
            _id3v2.TrackNumber       = Track;
            _id3v2.Header.TagVersion = ID3v2Version.Value;

            List <IAttachedPicture> deleteList = new List <IAttachedPicture>(_id3v2.PictureList);

            foreach (var picture in PictureCollection)
            {
                if (picture.AttachedPicture != null)
                {
                    picture.AttachedPicture.Description = picture.Description;
                    picture.AttachedPicture.PictureType = picture.PictureType;
                    deleteList.Remove(picture.AttachedPicture);
                }
                else
                {
                    IAttachedPicture apic = _id3v2.PictureList.AddNew();
                    apic.Description = picture.Description;
                    apic.PictureType = picture.PictureType;
                    apic.PictureData = picture.PictureBytes;
                }
            }

            foreach (var deletePicture in deleteList)
            {
                _id3v2.PictureList.Remove(deletePicture);
            }

            IComments comments = _id3v2.CommentsList.FirstOrDefault();

            if (!string.IsNullOrWhiteSpace(Comment))
            {
                if (comments == null)
                {
                    comments = _id3v2.CommentsList.AddNew();
                }
                comments.Value = Comment;
            }
            else
            {
                if (comments != null)
                {
                    _id3v2.CommentsList.Remove(comments);
                }
            }

            // TODO: Multiple comments

            _id3v2.Save(_fullFileName);
        }
Ejemplo n.º 6
0
        private void LoadImageData(IAttachedPicture attachedPicture)
        {
            pictureBox1.Image = attachedPicture.Picture;

            txtImageDescription.Text   = attachedPicture.Description;
            cmbImageType.SelectedIndex = cmbImageType.Items.IndexOf(PictureTypeHelper.GetStringFromPictureType(attachedPicture.PictureType));

            txtImageDescription.Enabled = true;
            cmbImageType.Enabled        = true;
        }
Ejemplo n.º 7
0
        private void LoadImageFromFile(IAttachedPicture attachedPicture)
        {
            DialogResult dialogResult = imageOpenFileDialog.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                attachedPicture.Picture = Image.FromFile(imageOpenFileDialog.FileName);
                pictureBox1.Image       = attachedPicture.Picture;
            }
        }
Ejemplo n.º 8
0
        private void bindingSource_CurrentChanged(object sender, EventArgs e)
        {
            IAttachedPicture attachedPicture = GetCurrentPictureFrame();

            if (attachedPicture != null)
            {
                LoadImageData(attachedPicture);
            }
            else
            {
                ClearImageData();
            }
        }
Ejemplo n.º 9
0
        private void SaveImageToFile(IAttachedPicture attachedPicture)
        {
            string extension = attachedPicture.PictureExtension;

            imageSaveFileDialog.FileName = "image." + extension;

            DialogResult dialogResult = imageSaveFileDialog.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                using (FileStream fs = File.Open(imageSaveFileDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    fs.Write(attachedPicture.PictureData, 0, attachedPicture.PictureData.Length);
                }
            }
        }
Ejemplo n.º 10
0
        private void OnSaveFile()
        {
            List <IAttachedPicture> deleteList = new List <IAttachedPicture>(ID3v2.PictureList);

            foreach (var picture in PictureCollection)
            {
                if (picture.AttachedPicture != null)
                {
                    picture.AttachedPicture.Description = picture.Description;
                    picture.AttachedPicture.PictureType = picture.PictureType;
                    deleteList.Remove(picture.AttachedPicture);
                }
                else
                {
                    IAttachedPicture apic = ID3v2.PictureList.AddNew();
                    apic.Description = picture.Description;
                    apic.PictureType = picture.PictureType;
                    apic.PictureData = picture.PictureBytes;
                }
            }

            foreach (var deletePicture in deleteList)
            {
                ID3v2.PictureList.Remove(deletePicture);
            }

            // TODO: Multiple comments

            /*IComments comments = _id3v2.CommentsList.FirstOrDefault();
             *
             * if (!string.IsNullOrWhiteSpace(Comment))
             * {
             *  if (comments == null)
             *  {
             *      comments = _id3v2.CommentsList.AddNew();
             *  }
             *  comments.Value = Comment;
             * }
             * else
             * {
             *  if (comments != null)
             *      _id3v2.CommentsList.Remove(comments);
             * }*/

            ID3v2.Save(FullFileName);
        }
Ejemplo n.º 11
0
        private static void CreatePictureOnUIThread(Track track, IAttachedPicture picture)
        {
            if (track == null)
            {
                throw new ArgumentNullException("track");
            }
            if (picture == null)
            {
                throw new ArgumentNullException("picture");
            }

            if (!Application.Current.Dispatcher.CheckAccess())
            {
                Application.Current.Dispatcher.Invoke(new Action <Track, IAttachedPicture>(CreatePictureOnUIThread), track, picture);
                return;
            }

            track.Picture = new Picture(picture);
        }
Ejemplo n.º 12
0
        public static Boolean Savev2tag(Track mytrack)
        {
            if (!File.Exists(mytrack.Filename))
            {
                MessageBox.Show("File Does not exist " + mytrack.Filename);
                return(false);
            }
            var trackxml = new XMLutils(appPath + "\\trackxml.xml");

            removeID3v2(mytrack.Filename);
            var id3 = new ID3v2Tag(mytrack.Filename);

            if (!String.IsNullOrEmpty(mytrack.Filename) && File.Exists(mytrack.Filename))
            {
                id3.Album       = mytrack.Album;
                id3.Artist      = mytrack.Artist;
                id3.Title       = mytrack.Title;
                id3.TrackNumber = mytrack.Trackno;
                id3.Year        = mytrack.Year;
                id3.Genre       = mytrack.Genre;

                if (mytrack.coverimage != null)
                {
                    id3.PictureList.Clear();
                    IAttachedPicture picture = id3.PictureList.AddNew();

                    picture.PictureData = ConvertBitMapToByteArray(mytrack.coverimage);
                    picture.PictureType = PictureType.CoverFront;
                }
                id3.Save(mytrack.Filename);
                trackxml.ModifyRecord(mytrack);
            }
            if (ID3v2Tag.DoesTagExist(mytrack.Filename))
            {
                trackxml.Updaterecord(mytrack.Filename);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 13
0
        private void SaveImageToFile(IAttachedPicture attachedPicture)
        {
            String extension = attachedPicture.PictureExtension;

            imageSaveFileDialog.FileName = "image." + extension;

            DialogResult dialogResult = imageSaveFileDialog.ShowDialog();
            if (dialogResult == DialogResult.OK)
            {
                using (FileStream fs = File.Open(imageSaveFileDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.None))
                {
                    fs.Write(attachedPicture.PictureData, 0, attachedPicture.PictureData.Length);
                }
            }
        }
Ejemplo n.º 14
0
 private void LoadImageFromFile(IAttachedPicture attachedPicture)
 {
     DialogResult dialogResult = imageOpenFileDialog.ShowDialog();
     if (dialogResult == DialogResult.OK)
     {
         attachedPicture.Picture = Image.FromFile(imageOpenFileDialog.FileName);
         pictureBox1.Image = attachedPicture.Picture;
     }
 }
Ejemplo n.º 15
0
        private void LoadImageData(IAttachedPicture attachedPicture)
        {
            pictureBox1.Image = attachedPicture.Picture;

            txtImageDescription.Text = attachedPicture.Description;
            cmbImageType.SelectedIndex = cmbImageType.Items.IndexOf(PictureTypeHelper.GetStringFromPictureType(attachedPicture.PictureType));

            txtImageDescription.Enabled = true;
            cmbImageType.Enabled = true;
        }
Ejemplo n.º 16
0
        private void ScanDirectory(object basePathObject)
        {
            int totalFiles = 0;
            ObservableCollection <Track> trackList = new ObservableCollection <Track>();

            try
            {
                string basePath = (string)basePathObject;

                DirectoryInfo di       = new DirectoryInfo(basePath);
                FileInfo[]    fileList = di.GetFiles("*.mp3", SearchOption.AllDirectories);

                totalFiles = fileList.Length;

                for (int i = 0; i < totalFiles; i++)
                {
                    if (_cancelScanning)
                    {
                        totalFiles = i;
                        break;
                    }

                    IID3v2Tag id3 = new ID3v2Tag(fileList[i].FullName);

                    Track track = new Track
                    {
                        Artist       = id3.Artist,
                        Title        = id3.Title,
                        Album        = id3.Album,
                        Year         = id3.Year,
                        Genre        = id3.Genre,
                        FullFileName = fileList[i].FullName
                    };

                    if (id3.PictureList != null && id3.PictureList.Count > 0)
                    {
                        IAttachedPicture picture = id3.PictureList[0];
                        if (picture.PictureType != PictureType.CoverFront)
                        {
                            foreach (var apic in id3.PictureList)
                            {
                                if (apic.PictureType == PictureType.CoverFront)
                                {
                                    picture = apic;
                                    break;
                                }
                            }
                        }

                        CreatePictureOnUIThread(track, picture);
                    }

                    trackList.Add(track);

                    double percent = i * 100.0 / totalFiles;
                    if (percent - PercentComplete >= 0.9 || (i % 100) == 0)
                    {
                        UpdateProgress(percent);
                    }
                }

                if (!_cancelScanning)
                {
                    UpdateProgress(100);
                }
            }
            finally
            {
                EndRecursiveScanning(totalFiles, trackList);
            }
        }
Ejemplo n.º 17
0
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            IAttachedPicture attachedPicture = GetCurrentPictureFrame();

            LoadImageFromFile(attachedPicture);
        }
Ejemplo n.º 18
0
        private void miLoadImage_Click(object sender, EventArgs e)
        {
            IAttachedPicture attachedPicture = GetCurrentPictureFrame();

            LoadImageFromFile(attachedPicture);
        }
Ejemplo n.º 19
0
        private static void CreatePictureOnUIThread(Track track, IAttachedPicture picture)
        {
            if (track == null)
                throw new ArgumentNullException("track");
            if (picture == null)
                throw new ArgumentNullException("picture");

            if (!Application.Current.Dispatcher.CheckAccess())
            {
                Application.Current.Dispatcher.Invoke(new Action<Track, IAttachedPicture>(CreatePictureOnUIThread), track, picture);
                return;
            }

            track.Picture = new Picture(picture);
        }
Ejemplo n.º 20
0
        private void miSaveImage_Click(object sender, EventArgs e)
        {
            IAttachedPicture attachedPicture = GetCurrentPictureFrame();

            SaveImageToFile(attachedPicture);
        }
Ejemplo n.º 21
0
        public static void UpdateId3(Music objEntity)
        {
            string path = string.Empty;

            if (string.IsNullOrWhiteSpace(objEntity.FilePath) == false && string.IsNullOrWhiteSpace(objEntity.FileName) == false)
            {
                path = Path.Combine(objEntity.FilePath, objEntity.FileName);
            }
            else if (string.IsNullOrWhiteSpace(objEntity.FilePath) == true && string.IsNullOrWhiteSpace(objEntity.FileName) == false)
            {
                path = objEntity.FileName;
            }
            else if (string.IsNullOrWhiteSpace(objEntity.FilePath) == false && string.IsNullOrWhiteSpace(objEntity.FileName) == true)
            {
                path = objEntity.FilePath;
            }

            if (string.IsNullOrWhiteSpace(path) == false)
            {
                if (Directory.Exists(path))
                {
                    int    index;
                    byte[] cover = RessourcesServices.GetDefaultCover(objEntity, out index);

                    DirectoryInfo folder = new DirectoryInfo(path);

                    FileInfo[] files = folder.GetFiles("*.mp3", SearchOption.TopDirectoryOnly);
                    files = files.Concat(folder.GetFiles("*.flc", SearchOption.TopDirectoryOnly)).ToArray();
                    files = files.Concat(folder.GetFiles("*.flac", SearchOption.TopDirectoryOnly)).ToArray();

                    if (files.Any())
                    {
                        foreach (FileInfo file in files)
                        {
                            switch (file.Extension)
                            {
                            case ".mp3":
                                IID3v2 objMp3Tag = ID3v2Helper.CreateID3v2(file.FullName);
                                if (objMp3Tag != null)
                                {
                                    objMp3Tag.Album         = objEntity.Album;
                                    objMp3Tag.Artist        = objEntity.Artists.First().FulleName;
                                    objMp3Tag.Accompaniment = objEntity.Artists.First().FulleName;

                                    Genre genre = objEntity.Genres.FirstOrDefault();
                                    if (genre != null)
                                    {
                                        objMp3Tag.Genre = genre.DisplayName;
                                    }


                                    if (cover != null)
                                    {
                                        while (objMp3Tag.PictureList.Any())
                                        {
                                            objMp3Tag.PictureList.Remove(objMp3Tag.PictureList[0]);
                                        }

                                        IAttachedPicture picture = objMp3Tag.PictureList.AddNew();
                                        if (picture != null)
                                        {
                                            picture.PictureData = cover;
                                            picture.PictureType = PictureType.CoverFront;     // optional
                                        }
                                    }
                                    objMp3Tag.Save(file.FullName);
                                }
                                break;

                            case ".flac":
                            case ".flc":
                                FlacTagger flacTaggerTag = new FlacTagger(file.FullName);
                                flacTaggerTag.Album     = objEntity.Album;
                                flacTaggerTag.Artist    = objEntity.Artists.First().FulleName;
                                flacTaggerTag.Performer = objEntity.Artists.First().FulleName;

                                Genre musicGenre = objEntity.Genres.FirstOrDefault();
                                if (musicGenre != null)
                                {
                                    flacTaggerTag.Genre = musicGenre.DisplayName;
                                }


                                if (cover != null)
                                {
                                    while (flacTaggerTag.Arts.Any())
                                    {
                                        flacTaggerTag.RemoveArt(flacTaggerTag.Arts[0]);
                                    }

                                    ID3PictureFrame picture = new ID3PictureFrame(cover, ID3PictureType.FrontCover);
                                    flacTaggerTag.AddArt(picture);
                                }
                                flacTaggerTag.SaveMetadata();
                                break;
                            }
                        }
                    }
                }
            }
        }