示例#1
0
        private void ShowMenuItem_Click(object sender, RoutedEventArgs e)
        {
            var item = sender as MenuItem;
            BindingList <Playlist> items = item.DataContext as BindingList <Playlist>;

            _tempPlaylist = items[_upIndex].Song;
            playlistpg    = new PlaylistPage(_tempPlaylist);
            Control.Show(MainContent, playlistpg);
        }
示例#2
0
        private void NextButton_Click(object sender, RoutedEventArgs e)
        {
            if (_currentlyPlayingPlayList.Count != 0)
            {
                if (currentlyPlayingSong != null)
                {
                    _audio.Stop();
                    _timer.Stop();
                    _audio.Close();
                    string nextSong = null;

                    if (_isShuffle == true)
                    {
                        Random rnd = new Random();

                        if (PlaylistPage.indexes.Count == 0)
                        {
                            PlaylistPage.refillIndexesList();
                        }

                        int position = rnd.Next(PlaylistPage.indexes.Count);

                        nextSong = PlaylistPage._Playlist[PlaylistPage.indexes[position]].FileName;

                        PlaylistPage.indexes.RemoveAt(position);
                    }
                    else if (_isShuffle == false)
                    {
                        for (int i = 0; i < _currentlyPlayingPlayList.Count(); i++)
                        {
                            if (currentlyPlayingSong == _currentlyPlayingPlayList[i].FileName)
                            {
                                if (i + 1 == _currentlyPlayingPlayList.Count())
                                {
                                    nextSong = _currentlyPlayingPlayList[0].FileName;
                                }
                                else
                                {
                                    nextSong = _currentlyPlayingPlayList[i + 1].FileName;
                                }
                            }
                        }
                    }

                    SetNowPlaying(nextSong);
                    _audio.MediaOpened += _audio_MediaOpened;
                    _audio.MediaEnded  += _audio_MediaEnded;
                }
            }
        }
示例#3
0
        private void ListViewItem_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            ListViewItem item = sender as ListViewItem;

            if (item != null && item.IsSelected)
            {
                if (item.Name == "MyMusic")
                {
                    Control.Show(MainContent, mymusicpg);
                }
                else if (item.Name == "NowPlaying")
                {
                    Control.Show(MainContent, new NowPlayingPage());
                }
                else
                {
                    int index = PlaylistListView.SelectedIndex;

                    if (index != -1)
                    {
                        Playlist items = item.Content as Playlist;
                        _globalname = items.Name;

                        if (items != null)
                        {
                            int i = 0;
                            foreach (var list in _playlistList)
                            {
                                if (list.Name == _globalname)
                                {
                                    list.Save(true, 0);
                                    _globalindex = i;
                                }
                                else
                                {
                                    list.Save();
                                }
                                i++;
                            }

                            _tempPlaylist = items._song;
                            playlistpg    = new PlaylistPage(_tempPlaylist);
                            Control.Show(MainContent, playlistpg);
                        }
                    }
                }
            }
        }
示例#4
0
        //Hook
        private void _hook_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == System.Windows.Forms.Keys.Space && _isPlaying == true)
            {
                Image  img  = new Image();
                string path = string.Format("/Icon/play.png");
                img.Source = new BitmapImage(new Uri(path, UriKind.Relative));
                img.Height = 40;
                img.Width  = 40;

                playButton.Content = img;

                _isPlaying = false;
                _audio.Pause();
                _timer.Stop();
            }
            else if (e.Control && e.KeyCode == System.Windows.Forms.Keys.Space && _isPlaying == false && e.Control)
            {
                Image  img  = new Image();
                string path = string.Format("/Icon/pause.png");
                img.Source = new BitmapImage(new Uri(path, UriKind.Relative));
                img.Height = 40;
                img.Width  = 40;

                playButton.Content = img;

                _isPlaying = true;
                _audio.Play();
                _timer.Start();
            }
            else if (e.Control && e.KeyCode == System.Windows.Forms.Keys.Right)
            {
                if (currentlyPlayingSong != null && _isHavingAPlayListRunning == true)
                {
                    _audio.Stop();
                    _timer.Stop();
                    _audio.Close();
                    string nextSong = null;

                    if (_isShuffle == true)
                    {
                        Random rnd = new Random();

                        if (PlaylistPage.indexes.Count == 0)
                        {
                            PlaylistPage.refillIndexesList();
                        }

                        int position = rnd.Next(PlaylistPage.indexes.Count);

                        nextSong = PlaylistPage._Playlist[PlaylistPage.indexes[position]].FileName;

                        PlaylistPage.indexes.RemoveAt(position);
                    }
                    else if (_isShuffle == false)
                    {
                        for (int i = 0; i < _currentlyPlayingPlayList.Count(); i++)
                        {
                            if (currentlyPlayingSong == _currentlyPlayingPlayList[i].FileName)
                            {
                                if (i + 1 == _currentlyPlayingPlayList.Count())
                                {
                                    nextSong = _currentlyPlayingPlayList[0].FileName;
                                }
                                else
                                {
                                    nextSong = _currentlyPlayingPlayList[i + 1].FileName;
                                }
                            }
                        }
                    }

                    SetNowPlaying(nextSong);
                    _audio.MediaOpened += _audio_MediaOpened;
                    _audio.MediaEnded  += _audio_MediaEnded;
                }
            }
            else if (e.Control && e.KeyCode == System.Windows.Forms.Keys.Left)
            {
                if (currentlyPlayingSong != null && _isHavingAPlayListRunning == true)
                {
                    _audio.Stop();
                    _timer.Stop();
                    _audio.Close();
                    string previousSong = null;

                    if (_isShuffle == true)
                    {
                        Random rnd = new Random();

                        if (PlaylistPage.indexes.Count == 0)
                        {
                            PlaylistPage.refillIndexesList();
                        }

                        int position = rnd.Next(PlaylistPage.indexes.Count);

                        previousSong = PlaylistPage._Playlist[PlaylistPage.indexes[position]].FileName;

                        PlaylistPage.indexes.RemoveAt(position);
                    }
                    else if (_isShuffle == false)
                    {
                        for (int i = 0; i < _currentlyPlayingPlayList.Count; i++)
                        {
                            if (currentlyPlayingSong == _currentlyPlayingPlayList[i].FileName)
                            {
                                if (i == 0)
                                {
                                    previousSong = _currentlyPlayingPlayList[_currentlyPlayingPlayList.Count - 1].FileName;
                                }
                                else
                                {
                                    previousSong = _currentlyPlayingPlayList[i - 1].FileName;
                                }
                            }
                        }
                    }
                    SetNowPlaying(previousSong);
                    _audio.MediaOpened += _audio_MediaOpened;
                    _audio.MediaEnded  += _audio_MediaEnded;
                }
            }
        }
示例#5
0
        //event
        private void _audio_MediaEnded(object sender, EventArgs e)
        {
            _isPlaying = false;
            _timer.Stop();
            Info nextSong = null;

            if (_isRepeat == true && _isShuffle == true)
            {
                Random rnd = new Random();

                if (PlaylistPage.indexes.Count == 0)
                {
                    PlaylistPage.refillIndexesList();
                }

                int position = rnd.Next(PlaylistPage.indexes.Count);

                nextSong = _currentlyPlayingPlayList[PlaylistPage.indexes[position]];

                PlaylistPage.indexes.RemoveAt(position);
            }
            else if (_isRepeat == true && _isShuffle == false)
            {
                for (int i = 0; i < _currentlyPlayingPlayList.Count; i++)
                {
                    if (currentlyPlayingSong == _currentlyPlayingPlayList[i].FileName)
                    {
                        if (i + 1 < _currentlyPlayingPlayList.Count)
                        {
                            nextSong = _currentlyPlayingPlayList[i + 1];
                        }
                        else if (i + 1 == _currentlyPlayingPlayList.Count)
                        {
                            nextSong = _currentlyPlayingPlayList[0];
                        }
                    }
                }
            }
            else if (_isRepeat == false && _isShuffle == true)
            {
                Random rnd = new Random();

                if (PlaylistPage.indexes.Count != 0)
                {
                    int position = rnd.Next(PlaylistPage.indexes.Count);

                    nextSong = PlaylistPage._Playlist[PlaylistPage.indexes[position]];

                    PlaylistPage.indexes.RemoveAt(position);
                }
            }
            else if (_isRepeat == false && _isShuffle == false)
            {
                for (int i = 0; i < _currentlyPlayingPlayList.Count; i++)
                {
                    if (MainWindow.currentlyPlayingSong == _currentlyPlayingPlayList[i].FileName)
                    {
                        if (i + 1 < _currentlyPlayingPlayList.Count && PlaylistPage.startIndex != i + 1)
                        {
                            nextSong = _currentlyPlayingPlayList[i + 1];
                        }
                        else if (i + 1 == _currentlyPlayingPlayList.Count && PlaylistPage.startIndex != 0)
                        {
                            nextSong = _currentlyPlayingPlayList[0];
                        }
                    }
                }
            }

            if (nextSong != null)
            {
                MainWindow._audio.Close();
                MainWindow.SetNowPlaying(nextSong.FileName);
            }
        }