Ejemplo n.º 1
0
        /**
         * Click on the search button Abort track current and update track current with searched track init and play song
         */
        private void SearchClick(object sender, EventArgs e)
        {
            bool trackFound = false;

            if (waveOutEvent != null)
            {
                string item = textFieldSearch.Text;
                foreach (Track track in tracks)
                {
                    if (item == track.Title)
                    {
                        trackFound = true;
                        if (waveOutEvent.PlaybackState == PlaybackState.Playing)
                        {
                            waveOutEvent.Pause();
                            waveOutEvent = new WaveOutEvent();
                            if (threadTrackCurrent.ThreadState == ThreadState.Running)
                            {
                                threadTrackCurrent.Abort();
                                threadSeekBar.Abort();
                                threadTimeCurrent.Abort();
                            }
                            buttonPlay.Image = Image.FromFile("iconPlay.png");
                        }
                        else if (waveOutEvent.PlaybackState == PlaybackState.Paused)
                        {
                            if (threadTrackCurrent.ThreadState == ThreadState.Aborted || threadTrackCurrent.ThreadState == ThreadState.Suspended)
                            {
                                threadTrackCurrent.Start();
                                threadSeekBar.Start();
                                threadTimeCurrent.Start();
                            }
                            waveOutEvent.Play();
                            buttonPlay.Image = Image.FromFile("iconPause2.png");
                        }
                        waveOutEvent.Dispose();
                        waveOutEvent = null;
                        trackCurrent = null;

                        InfoTrack searchTrack = new InfoTrack(GetTrackSearch);
                        trackNext = searchTrack(tracks, track.Id);

                        trackCurrent      = new Track();
                        trackCurrent.File = trackNext.File;
                        trackCurrent.Path = trackNext.Path;
                        trackCurrent.getMetaDataTrack();
                        PlayMusic();
                    }
                }
            }
            if (!trackFound)
            {
                MessageBox.Show("The song you are looking for was not found");
            }
        }
Ejemplo n.º 2
0
        /**
         * Click on the Next button Abort track current and update track current with next track init and play song
         */
        private void NextClick(object sender, EventArgs e)
        {
            if (waveOutEvent != null)
            {
                if (waveOutEvent.PlaybackState == PlaybackState.Playing)
                {
                    threadTrackCurrent.Abort();
                    waveOutEvent.Pause();
                    waveOutEvent = new WaveOutEvent();
                }
                string item = trackCurrent.Title;
                foreach (Track track in tracks)
                {
                    if (item == track.Title)
                    {
                        if (waveOutEvent.PlaybackState == PlaybackState.Playing)
                        {
                            waveOutEvent.Pause();
                            if (threadTrackCurrent.ThreadState == ThreadState.Running)
                            {
                                threadTimeCurrent.Abort();
                                threadSeekBar.Abort();
                                threadTrackCurrent.Abort();
                            }
                            buttonPlay.Image = Image.FromFile("iconPlay.png");
                        }
                        else if (waveOutEvent.PlaybackState == PlaybackState.Paused)
                        {
                            if (threadTrackCurrent.ThreadState == ThreadState.Aborted || threadTrackCurrent.ThreadState == ThreadState.Suspended)
                            {
                                threadTrackCurrent.Start();
                                threadSeekBar.Start();
                                threadTimeCurrent.Start();
                            }
                            waveOutEvent.Play();
                            buttonPlay.Image = Image.FromFile("iconPause2.png");
                        }
                        waveOutEvent.Dispose();
                        waveOutEvent = null;
                        trackCurrent = null;

                        InfoTrack nextTrack = new InfoTrack(GetNextTrack);
                        trackNext = nextTrack(tracks, track.Id);

                        trackCurrent      = new Track();
                        trackCurrent.File = trackNext.File;
                        trackCurrent.Path = trackNext.Path;
                        trackCurrent.getMetaDataTrack();
                        PlayMusic();
                    }
                }
            }
        }