Ejemplo n.º 1
0
        private void SortByArtistToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var SortedList = Music.OrderBy(x => TagFile.GetArtists(x)).ThenBy(x => TagFile.GetAlbum(x)).ThenBy(x => TagFile.GetTrack(x)).ToList();

            // The only reason make me keep All this Code bellow on comment, is that i found a better and small way to do it (The Line upove)
            #region The Comment Code

            /*  //  I use the OrderBy function and the Linq, to sort the list on the Album
             * List<string> MusicListCopy = Music.OrderBy(o => TagFile.Album(o)).ToList();
             * List<string> AllAlbumsName = new List<string>();
             *
             * foreach (var item in MusicListCopy)
             *  AllAlbumsName.Add(TagFile.Album(item));
             * //  Reamove all the rapeated AlbumName on the list
             * AllAlbumsName = AllAlbumsName.Distinct().ToList();
             *
             * List<string> SortedList = new List<string>();
             * List<string> OnlyOneAlbumMusic = new List<string>();
             *
             * foreach (var ItemInAllAlbumsName in AllAlbumsName)
             * {
             *  foreach (var ItemInMusic in Music)
             *  {
             *      if (TagFile.Album(ItemInMusic) == ItemInAllAlbumsName)
             *      {
             *          OnlyOneAlbumMusic.Add(ItemInMusic);
             *          MusicListCopy.Remove(ItemInMusic);
             *      }
             *  }
             *
             *  OnlyOneAlbumMusic = OnlyOneAlbumMusic.OrderBy(o => TagFile.Track(o)).ToList();
             *
             *  foreach (var item in OnlyOneAlbumMusic)
             *      SortedList.Add(item);
             *  OnlyOneAlbumMusic.Clear();
             * }
             *
             * SortedList = SortedList.OrderBy(o => TagFile.Artist(o)).ToList();   */
            #endregion

            // Clear the Lists and initialize the index and waveoutevent to null
            ClearListToolStripMenuItem.PerformClick();

            //  Initialize the list and Play the first music
            AddItemsInListToTheMainList(SortedList);

            LastSortedMethode = SortedMethode.Artist;

            SortByArtistToolContextMenuStriItem.Checked = true;
            SortByTitleToolContextMenuStriItem.Checked  = false;
            SortByAlbumToolContextMenuStriItem.Checked  = false;

            ArtistToolStripMenuItem.Checked = true;
            TitleToolStripMenuItem.Checked  = false;
            AlbumToolStripMenuItem.Checked  = false;
        }
Ejemplo n.º 2
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (TextBoxTitle.Tag.ToString() == "Ok")
                {
                    TagFile.SetTitle(MainForm.Music[CurrentPlayingMusicIndex], TextBoxTitle.Text);
                    TextBoxTitle.Tag = "";
                }

                if (TextBoxArtists.Tag.ToString() == "Ok")
                {
                    TagFile.SetArtists(MainForm.Music[CurrentPlayingMusicIndex], TextBoxArtists.Text);
                    TextBoxArtists.Tag = "";
                }

                try
                {
                    if (TextBoxAlbum.Tag.ToString() == "Ok")
                    {
                        TagFile.SetAlbum(MainForm.Music[CurrentPlayingMusicIndex], TextBoxAlbum.Text);
                        TextBoxAlbum.Tag = "";
                    }
                }
                catch (NullReferenceException)
                {
                    //  Add Code later
                }
                catch (Exception Exc)
                {
                    MessageBox.Show(Exc.ToString(), "====:TextBoxAlbum:====");
                    MessageBox.Show(Exc.GetType().ToString(), "====:TextBoxAlbum:====");
                }

                if (TextBoxTrack.Tag.ToString() == "Ok")
                {
                    TagFile.SetTrackN(MainForm.Music[CurrentPlayingMusicIndex], TextBoxTrack.Text);
                    TextBoxTrack.Tag = "";
                }

                if (TextBoxTrackCount.Tag.ToString() == "Ok")
                {
                    TagFile.SetTrackCount(MainForm.Music[CurrentPlayingMusicIndex], TextBoxTrackCount.Text);
                    TextBoxTrackCount.Tag = "";
                }

                if (TextBoxYear.Tag.ToString() == "Ok")
                {
                    TagFile.SetYear(MainForm.Music[CurrentPlayingMusicIndex], TextBoxYear.Text);
                    TextBoxYear.Tag = "";
                }

                if (TextBoxGenre.Tag.ToString() == "Ok")
                {
                    TagFile.SetGenre(MainForm.Music[CurrentPlayingMusicIndex], TextBoxGenre.Text);
                    TextBoxGenre.Tag = "";
                }

                try
                {
                    if (PictureBoxCover.Tag.ToString() == "Ok")
                    {
                        TagFile.SetCover(MainForm.Music[CurrentPlayingMusicIndex], PictureBoxCover.Image);
                        PictureBoxCover.Tag = "";
                    }
                }
                catch (NullReferenceException)
                {
                    //  Add Code later
                }
                catch (Exception Exc)
                {
                    MessageBox.Show(Exc.ToString(), "====:PictureBoxCover:====");
                    MessageBox.Show(Exc.GetType().ToString(), "====:PictureBoxCover:====");
                }

                TagFile.SetLyrics(MainForm.Music[CurrentPlayingMusicIndex], RichTextBoxLyrics.Text);

                MessageBox.Show("All Tags Saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "====:Save:====");
                MessageBox.Show(ex.GetType().ToString(), "====:Save:====");
            }
        }
Ejemplo n.º 3
0
        private void MusicInitialize(string path)
        {
            if (WaveOutEvent != null)
            {
                WaveOutEvent.Dispose();
            }
            if (AudioFileReader != null)
            {
                AudioFileReader.Dispose();
            }

            try
            {
                AudioFileReader = new AudioFileReader(path);
                WaveOutEvent    = new WaveOutEvent();
                WaveOutEvent.Init(AudioFileReader);
                WaveOutEvent.Play();

                if (!AppTimer.Enabled)
                {
                    AppTimer.Start();
                }

                MusicState = MusicState.Play;
                ButtonPlayPause.BackgroundImage    = Properties.Resources.Pause;
                PlayAndPauseToolStripMenuItem.Text = "Pause";

                PlaybackBarControl.Max = Convert.ToInt32(ConvertFrom.TimeToSeconds(AudioFileReader.TotalTime));
                AudioFileReader.Volume = TrackBarVolumeState.Value / 10f;

                //  This condition is related to the (Exception) Code Part
                //  The Path Variable will be changed to the CurrentPlayingMusic, for get the original audio meatdata
                if (IsFileGenerateException)
                {
                    path = Music[CurrentPlayingMusicIndex];
                }

                //  Change the Label Text to the Music Total Time
                //  Change the PictureBox BackgroundImage to the Music Cover
                LabelMusicEndTime.Text = AudioFileReader.TotalTime.ToString(@"mm\:ss");
                PictureBoxMusicCover.BackgroundImage = TagFile.GetCover(path);

                //  Change the Form Title to the Music Title + Artist
                this.Text = TagFile.GetArtists(path) + " - " + TagFile.GetTitle(path);

                //  Change the Current MusicPanel BackgroundColor, and reset the others
                foreach (MusicPanel musicPanel in FlowLayoutPanelMusic.Controls)
                {
                    if (musicPanel.MusicPath == path)
                    {
                        musicPanel.BackColor = Color.FromArgb(28, 28, 28);
                    }
                    else
                    {
                        musicPanel.BackColor = Color.Transparent;
                    }
                }

                //  Reset the "IsFileGenerateException" value to false
                IsFileGenerateException = false;
            }
            catch
            {
                try
                {
                    //  If Audio File GenerateException, Convert it to 'wav' and save it
                    //  on a Temp File, so we can play it later
                    AudioFileReader = null;

                    using (var reader = new MediaFoundationReader(Music[CurrentPlayingMusicIndex]))
                    {
                        if (!Directory.Exists("TempFiles/"))
                        {
                            Directory.CreateDirectory("TempFiles/");
                        }

                        //  Save the 'wav' audio on the Temp File
                        WaveFileWriter.CreateWaveFile("TempFiles/temp.wav", reader);
                    }

                    //  Change the "IsFileGenerateException" value to true, because the File is Generate Exception
                    IsFileGenerateException = true;

                    //  Try to play the Temp File, if isn't played alert a message to the user
                    MusicInitialize("TempFiles/temp.wav");
                }
                catch (Exception Ex)
                {
                    MessageBox.Show("This song is hard for us to play it for you, Please play another one." + Environment.NewLine + "(" + Ex.Message + ")",
                                    "We are sorry!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }