private void SetCurrentPlayingSong(List <StorageFile> tracks, int currentPlayingSong)
 {
     if (tracks.Count > currentPlayingSong)
     {
         MusicPlayerController.SelectNewSource(player, tracks[currentPlayingSong]);
     }
 }
        private async void PlayNewSong_MediaEnded(MediaPlayer sender, object args)
        {
            timer.Change(Timeout.Infinite, Timeout.Infinite);
            bool isPlayingPlaylistTrack = playingMode == PlayingMode.PLAYLIST;

            MusicPlayerController.ReinitiatePlayer(ref player);
            player.MediaEnded += PlayNewSong_MediaEnded;
            if (isPlayingPlaylistTrack)
            {
                currentPlayingSongPlaylistIndex++;
                SetCurrentPlayingSong(playlistTracks, currentPlayingSongPlaylistIndex);
            }
            else
            {
                currentPlayingSongMusicLibraryIndex++;
                SetCurrentPlayingSong(musicLibrary, currentPlayingSongMusicLibraryIndex);
            }



            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                        () =>
            {
                dataGrid.SelectedIndex = isPlayingPlaylistTrack ? currentPlayingSongPlaylistIndex : currentPlayingSongMusicLibraryIndex;
                timelineSlider.Value   = 0;
            }
                                                                                                        );

            await MusicPlayerController.PlayAsync(player);

            UpdateTimelineSlider();
        }
        private async void PlaySongFromGrid_DoubleClick(object sender, DoubleTappedRoutedEventArgs ev)
        {
            string      paths = ((Song)dataGrid.SelectedItem).Path;
            StorageFile file  = await StorageFile.GetFileFromPathAsync(paths);

            MusicPlayerController.ReinitiatePlayer(ref player);
            player.MediaEnded += PlayNewSong_MediaEnded;
            MusicPlayerController.SelectNewSource(player, file);
            await MusicPlayerController.PlayAsync(player);

            SetCurrentPlayingSongIndex();
            timelineSlider.Value = 0;
            timelineSlider.ManipulationCompleted += SeekPositionSlider_ManipulationCompleted;
            UpdateTimelineSlider();
        }
        private void PlayNextSongButton_Click(object sender, RoutedEventArgs e)
        {
            MusicPlayerController.ReinitiatePlayer(ref player);
            player.MediaEnded += PlayNewSong_MediaEnded;

            if (++currentPlayingSongPlaylistIndex < playlistTracks.Count && playingMode == PlayingMode.PLAYLIST)
            {
                player.SetFileSource(playlistTracks[currentPlayingSongPlaylistIndex]);
                dataGrid.SelectedIndex = currentPlayingSongPlaylistIndex;
            }
            else if (++currentPlayingSongMusicLibraryIndex < musicLibrary.Count)
            {
                player.SetFileSource(musicLibrary[currentPlayingSongMusicLibraryIndex]);
                dataGrid.SelectedIndex = currentPlayingSongMusicLibraryIndex;
            }
            timelineSlider.Value = 0;
            player.Play();
        }
示例#5
0
        private async void PlaySongFromGrid_DoubleClick(object sender, DoubleTappedRoutedEventArgs ev)
        {
            string      paths = ((Song)dataGrid.SelectedItem).Path;
            StorageFile file  = await StorageFile.GetFileFromPathAsync(paths);

            MusicPlayerController.ReinitiatePlayer(ref player);
            player.MediaEnded += PlayNewSong_MediaEnded;


            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
                                                                                                        async() =>
            {
                MusicPlayerController.SelectNewSource(player, file);
                await MusicPlayerController.PlayAsync(player);
            }
                                                                                                        );

            SetCurrentPlayingSongIndex();
            timelineSlider.Value = 0;
            timelineSlider.ManipulationCompleted += SeekPositionSlider_ManipulationCompleted;
            UpdateTimelineSlider();
        }
 private async void Continue_playing(object sender, RoutedEventArgs e)
 {
     UpdateTimelineSlider();
     await MusicPlayerController.PlayAsync(player);
 }
 private void Button_Click_Stop(object sender, RoutedEventArgs e)
 {
     timer.Change(Timeout.Infinite, Timeout.Infinite);
     MusicPlayerController.PausePlayer(player);
 }