Ejemplo n.º 1
0
        private void RemoveFromListToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //  Search for the clicked MusicPanel and remove it
            foreach (MusicPanel musicPanel in FlowLayoutPanelMusic.Controls)
            {
                if (musicPanel.BackColor == Color.FromArgb(28, 28, 28))
                {
                    //  if the removed MusicPanel is the Playong Music, Start the next one
                    if (musicPanel.MusicPath == Music[CurrentPlayingMusicIndex])
                    {
                        ButtonNext.PerformClick();
                    }

                    Music.Remove(musicPanel.MusicPath);
                    FlowLayoutPanelMusic.Controls.Remove(musicPanel);

                    if (Music.Count == 0)
                    {
                        ClearListToolStripMenuItem_Click(sender, e);
                    }

                    break;
                }
            }

            //  Initialize the CurrentPlayingMusicIndex with the correct index
            for (int i = 0; i < Music.Count; i++)
            {
                if (this.Text == (TagFile.GetArtists(Music[i]) + " - " + TagFile.GetTitle(Music[i])))
                {
                    CurrentPlayingMusicIndex = i;
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        private void LyricsForm_Load(object sender, EventArgs e)
        {
            RichTextBoxLyrics.Text = TagFile.GetLyrics(MusicPath);
            this.Text = TagFile.GetArtists(MusicPath) + " - " + TagFile.GetTitle(MusicPath) + " :Lyrics:";

            RichTextBoxLyrics.SelectAll();
            RichTextBoxLyrics.SelectionAlignment = HorizontalAlignment.Center;
        }
Ejemplo n.º 3
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.º 4
0
        private void EditFormInitialise(int Index)
        {
            TextBoxGenre.AutoCompleteCustomSource.AddRange(TagLib.Genres.Audio);

            string TrackPath = MainForm.Music[Index];

            TextBoxTitle.Text      = TagFile.GetTitle(TrackPath);
            TextBoxArtists.Text    = TagFile.GetArtists(TrackPath);
            TextBoxAlbum.Text      = TagFile.GetAlbum(TrackPath);
            TextBoxTrack.Text      = TagFile.GetTrack(TrackPath);
            TextBoxTrackCount.Text = TagFile.GetTrackCount(TrackPath);
            TextBoxGenre.Text      = TagFile.GetGenre(TrackPath);
            RichTextBoxLyrics.Text = TagFile.GetLyrics(TrackPath);
            PictureBoxCover.Image  = TagFile.GetCover(TrackPath);
            TextBoxYear.Text       = TagFile.GetYear(TrackPath);

            this.Text = TextBoxTitle.Text;
        }
Ejemplo n.º 5
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);
                }
            }
        }