private async void MyMediaElement_MediaEnded(object sender, RoutedEventArgs e)
        {
            if (isThisPageActive)
            {
                if (currentItemIndex < playlist.Count - 1)
                {
                    // Current media must've been playing if we received an event about it ending.
                    // The design of this sample scenario is to automatically start playing the next
                    // item in the playlist.  So we'll set the AutoPlay property to true, then in
                    // SetNewMediaItem() when we eventually call SetSource() on the XAML MediaElement
                    // control, it will automatically playing the new media item.
                    MyMediaElement.AutoPlay = true;
                    await SetNewMediaItem(currentItemIndex + 1);
                }
                else
                {
                    // End of playlist reached.
                    if (repeatPlaylist)
                    {
                        // Playlist repeat was selected so start again.
                        MyMediaElement.AutoPlay = true;
                        await SetNewMediaItem(0);

                        rootPage.NotifyUser("end of playlist, starting playback again at beginning of playlist", NotifyType.StatusMessage);
                    }
                    else
                    {
                        // Repeat wasn't selected so just stop playback.
                        MyMediaElement.AutoPlay = false;
                        MyMediaElement.Stop();
                        rootPage.NotifyUser("end of playlist, stopping playback", NotifyType.StatusMessage);
                    }
                }
            }
        }
Esempio n. 2
0
 private void MyMediaElementOnMediaEnded(object sender, EventArgs eventArgs)
 {
     if (IsRepeatEnable)
     {
         MyMediaElement.Stop();
         _timer.Stop();
         Position = 0;
         Thread.Sleep(100);
         StartTime = "0:00";
         IsPlay    = true;
         ChangePlayState(true);
     }
     else
     {
         MyMediaElement.Stop();
         _timer.Stop();
         Thread.Sleep(100);
         Position  = 0;
         StartTime = "0:00";
         if (OnCanExecuteNextTrackCommand(null))
         {
             ChangeTrack(true);
         }
         else
         {
             IsPlay = false;
         }
     }
 }
        private void StopButton_Click(object sender, RoutedEventArgs e)
        {
            MyMediaElement.Stop();
            Symbol     pico  = Symbol.Play;
            SymbolIcon spico = new SymbolIcon(pico);

            Play.Icon = spico;
        }
Esempio n. 4
0
        private async void SongGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            // Ignore clicks when we are in cooldown
            if (!_playingMusic)
            {
                return;
            }

            CountDown.Pause();
            MyMediaElement.Stop();

            var clickedSong = (Song)e.ClickedItem;
            var correctSong = Songs.FirstOrDefault(p => p.Selected == true);

            // Evaluate the user's selection

            Uri uri;
            int score;

            if (clickedSong.Selected)
            {
                uri   = new Uri("ms-appx:///Assets/correct.png");
                score = (int)MyProgressBar.Value;
            }
            else
            {
                uri   = new Uri("ms-appx:///Assets/incorrect.png");
                score = ((int)MyProgressBar.Value) * -1;
            }
            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);

            var fileStream = await file.OpenAsync(FileAccessMode.Read);

            await clickedSong.AlbumCover.SetSourceAsync(fileStream);

            _totalScore += score;
            _round++;

            ResultTextBlock.Text = string.Format("Score: {0} Total Score after {1} Rounds: {2}", score, _round, _totalScore);
            TitleTextBlock.Text  = String.Format("Correct Song: {0}", correctSong.Title);
            ArtistTextBlock.Text = string.Format("Performed by: {0}", correctSong.Artist);
            AlbumTextBlock.Text  = string.Format("On Album: {0}", correctSong.Album);

            clickedSong.Used = true;

            correctSong.Selected = false;
            correctSong.Used     = true;

            if (_round >= 5)
            {
                InstructionTextBlock.Text  = string.Format("Game over ... You scored: {0}", _totalScore);
                PlayAgainButton.Visibility = Visibility.Visible;
            }
            else
            {
                StartCooldown();
            }
        }
Esempio n. 5
0
        private async void SongGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            // Ignore clicks when we are in cooldown
            if (!_playingMusic)
            {
                return;
            }

            CountDown.Pause();
            MyMediaElement.Stop();

            Song clickedSong = (Song)e.ClickedItem;
            Song correctSong = Songs.FirstOrDefault(p => p.Selected);

            // Evaluate the user's selection
            Uri uri      = null;
            int addScore = 0;

            if (clickedSong.Selected)
            {
                uri      = new Uri("ms-appx:///Assets/correct.png");
                addScore = (int)MyProgressBar.Value;
            }
            else
            {
                uri      = new Uri("ms-appx:///Assets/incorrect.png");
                addScore = (-1) * (int)MyProgressBar.Value;
            }


            // Setting the picture.
            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);

            var fileStream = await file.OpenAsync(FileAccessMode.Read);

            await clickedSong.AlbumCover.SetSourceAsync(fileStream);

            DisplayCorrectSong(correctSong);

            _totalScore += addScore;
            _round++;
            ResultTextBlock.Text = String.Format("Score: {0}, Total Score after {1} Rounds: {2}", addScore, _round, _totalScore);

            clickedSong.Used     = true;
            correctSong.Selected = false;
            correctSong.Used     = true;

            if (_round > _max_round)
            {
                InstructionTextBlock.Text  = String.Format("Game Over... You scored: {0}", _totalScore);
                PlayAgainButton.Visibility = Visibility.Visible;
            }
            else
            {
                StartCooldown();
            }
        }
Esempio n. 6
0
 private void btnStop_Click(object sender, RoutedEventArgs e)
 {
     MyMediaElement.Stop();
     isPlaying = false;
     //musicPlays = MusicPlays.Stop;
     btnPause.IsEnabled = false;
     btnPlay.IsEnabled  = true;
     btnStop.IsEnabled  = false;
 }
Esempio n. 7
0
 private void ChangeTrack(bool next)
 {
     if (!IsShuffleEnable)
     {
         if (next)
         {
             _trackIndex   = _trackIndex + 1;
             CurrentTrack  = TrackModelList[_trackIndex];
             SelectedTrack = CurrentTrack;
         }
         else
         {
             _trackIndex   = _trackIndex - 1;
             CurrentTrack  = TrackModelList[_trackIndex];
             SelectedTrack = CurrentTrack;
         }
     }
     else
     {
         if (next)
         {
             var random      = new Random();
             var randomDigit = random.Next(0, TrackModelList.Count - 1);
             _trackIndex   = randomDigit;
             PreviousTrack = CurrentTrack;
             CurrentTrack  = TrackModelList[_trackIndex];
         }
         else
         {
             var random      = new Random();
             var randomDigit = random.Next(0, TrackModelList.Count - 1);
             if (PreviousTrack == null)
             {
                 _trackIndex   = randomDigit;
                 CurrentTrack  = TrackModelList[_trackIndex];
                 PreviousTrack = TrackModelList[random.Next(0, TrackModelList.Count - 1)];
             }
             else
             {
                 CurrentTrack  = PreviousTrack;
                 _trackIndex   = randomDigit;
                 PreviousTrack = TrackModelList[_trackIndex];
             }
         }
     }
     MyMediaElement.Stop();
     _timer.Stop();
     MyMediaElement.Open(new Uri(CurrentTrack.Path, UriKind.Relative));
     Position = 0;
     Thread.Sleep(100);
     StartTime = "0:00";
     IsPlay    = true;
     ChangePlayState(true);
 }
 public void StopSong(Song s)
 {
     MyMediaElement.Stop();
     IsPlay = false;
     PlayOrPause.Content = new Image {
         Source = new BitmapImage(new Uri(MediaPath.Play))
     };
     PlayOrPause.ToolTip = "Pause";
     GideonBase.SynObj.SpeakAsync("MediaPlayer has been stopped!");
     s.SongName = songname;
 }
Esempio n. 9
0
        private async void systemMediaControls_ButtonPressed(SystemMediaTransportControls sender, SystemMediaTransportControlsButtonPressedEventArgs args)
        {
            // The system media transport control's ButtonPressed event may not fire on the app's UI thread.  XAML controls
            // (including the MediaElement control in our page as well as the scenario page itself) typically can only be
            // safely accessed and manipulated on the UI thread, so here for simplicity, we dispatch our entire event handling
            // code to execute on the UI thread, as our code here primarily deals with updating the UI and the MediaElement.
            //
            // Depending on how exactly you are handling the different button presses (which for your app may include buttons
            // not used in this sample scenario), you may instead choose to only dispatch certain parts of your app's
            // event handling code (such as those that interact with XAML) to run on UI thread.
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                // Because the handling code is dispatched asynchronously, it is possible the user may have
                // navigated away from this scenario page to another scenario page by the time we are executing here.
                // Check to ensure the page is still active before proceeding.
                if (isThisPageActive)
                {
                    switch (args.Button)
                    {
                    case SystemMediaTransportControlsButton.Play:
                        //rootPage.NotifyUser("Play pressed", NotifyType.StatusMessage);
                        MyMediaElement.Play();
                        break;

                    case SystemMediaTransportControlsButton.Pause:
                        //rootPage.NotifyUser("Pause pressed", NotifyType.StatusMessage);
                        MyMediaElement.Pause();
                        break;

                    case SystemMediaTransportControlsButton.Stop:
                        //rootPage.NotifyUser("Stop pressed", NotifyType.StatusMessage);
                        MyMediaElement.Stop();
                        break;

                    case SystemMediaTransportControlsButton.Next:
                        //rootPage.NotifyUser("Next pressed", NotifyType.StatusMessage);
                        // range-checking will be performed in SetNewMediaItem()
                        await SetNewMediaItem(currentItemIndex + 1);
                        break;

                    case SystemMediaTransportControlsButton.Previous:
                        //rootPage.NotifyUser("Previous pressed", NotifyType.StatusMessage);
                        // range-checking will be performed in SetNewMediaItem()
                        await SetNewMediaItem(currentItemIndex - 1);
                        break;

                        // Insert additional case statements for other buttons you want to handle in your app.
                        // Remember that you also need to first enable those buttons via the corresponding
                        // Is****Enabled property on the SystemMediaTransportControls object.
                    }
                }
            });
        }
Esempio n. 10
0
 void _timer_Tick(object state)
 {
     this.Dispatcher.BeginInvoke(delegate()
     {
         var endSecond          = (int)slider1.Value + (int)slider2.Value;
         var sc                 = new SecondsToFormattedTimeConverter();
         int n                  = (int)MyMediaElement.Position.TotalSeconds;
         tbCurrentPosition.Text = (n / 60).ToString().PadLeft(2, '0') + ":" + (n % 60).ToString().PadLeft(2, '0');
         if (MyMediaElement.Position.TotalSeconds >= endSecond)
         {
             MyMediaElement.Stop();
         }
     });
 }
Esempio n. 11
0
        private void PlayTrack(object o)
        {
            var track = o as TrackListModel;

            CurrentTrack = track;
            _trackIndex  = TrackModelList.IndexOf(track);
            MyMediaElement.Open(new Uri(CurrentTrack.Path, UriKind.Relative));
            MyMediaElement.Stop();
            Position = 0;
            Thread.Sleep(100);
            StartTime = "0:00";
            IsPlay    = true;
            ChangePlayState(true);
        }
Esempio n. 12
0
 public PlayerViewModel()
 {
     TrackModelList = new ObservableCollection <TrackListModel>();
     InitializeTrackList();
     _timer.Interval = TimeSpan.FromMilliseconds(1000);
     _timer.Tick    += TimerPosition;
     CurrentTrack    = TrackModelList.First();
     SelectedTrack   = CurrentTrack;
     _trackIndex     = 0;
     MyMediaElement.Open(new Uri(CurrentTrack.Path, UriKind.Relative));
     MyMediaElement.Stop();
     MyMediaElement.MediaOpened += MyMediaElementOnMediaOpened;
     MyMediaElement.MediaEnded  += MyMediaElementOnMediaEnded;
     MyMediaElement.Volume       = Volume;
 }
Esempio n. 13
0
        private void btnPlay_Click(object sender, RoutedEventArgs e)
        {
            if (MyMediaElement.CurrentState == MediaElementState.Playing)
            {
                MyMediaElement.Stop();
                return;
            }
            int n = (int)slider1.Value;

            tbCurrentPosition.Text = (n / 60).ToString().PadLeft(2, '0') + ":" + (n % 60).ToString().PadLeft(2, '0');
            if (BasicStates.CurrentState.Name != "CutRingtonePage_Playing")
            {
                VisualStateManager.GoToState(this, "CutRingtonePage_Playing", true);
            }
            var thread = new Thread(PrePlayThread);

            thread.Start(viewModel.CurrentSong);
        }
Esempio n. 14
0
        private void MyMediaElementOnMediaOpenedPreview(object sender, EventArgs eventArgs)
        {
            var duration =
                $"{MyMediaElement.NaturalDuration.TimeSpan.Minutes}:{GetCorrectSeconds(MyMediaElement.NaturalDuration.TimeSpan.Seconds)}";
            var path = MyMediaElement.Source.OriginalString;

            if (path == TrackModelList.Last().Path)
            {
                MyMediaElement.MediaOpened -= MyMediaElementOnMediaOpenedPreview;
                MyMediaElement.Open(new Uri(CurrentTrack.Path, UriKind.Relative));
                MyMediaElement.Stop();
                MyMediaElement.MediaOpened += MyMediaElementOnMediaOpened;
                MyMediaElement.MediaEnded  += MyMediaElementOnMediaEnded;
                MyMediaElement.Volume       = Volume;
            }

            TrackModelList.First(x => x.Path == path).Duration = duration;
        }
Esempio n. 15
0
        private async void CountDown_Completed(object sender, object e)
        {
            if (!_playingMusic)
            {
                // Start playing music
                var song = PickSong();

                // Play the music
                MyMediaElement.SetSource(
                    await song.SongFile.OpenAsync(FileAccessMode.Read),
                    song.SongFile.ContentType);

                // Start countdown
                StartCountdown();
            }
            else
            {
                MyMediaElement.Stop();
                Song correctSong = Songs.FirstOrDefault(p => p.Selected);
                correctSong.Selected = false;
                correctSong.Used     = true;
                DisplayCorrectSong(correctSong);
                int addScore = (-1) * (int)MyProgressBar.Value;
                _totalScore += addScore;
                _round++;
                ResultTextBlock.Text = String.Format("Score: {0}, Total Score after {1} Rounds: {2}", addScore, _round, _totalScore);
                if (_round >= 5)
                {
                    InstructionTextBlock.Text  = String.Format("Game Over... You scored: {0}", _totalScore);
                    PlayAgainButton.Visibility = Visibility.Visible;
                }
                else
                {
                    StartCooldown();
                }
            }
        }
Esempio n. 16
0
        private async void SongGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            // Ignore clicks when loading new song
            if (!playmusic)
            {
                return;
            }

            CountDown.Pause();
            MyMediaElement.Stop();

            var clickedSong = (Song)e.ClickedItem;
            var correctSong = Songs.FirstOrDefault(p => p.Selected == true);

            // Correct and Incorrect answers
            // Produces the png pictures once right or wrong answers are clicked
            // A URI is used to indentify a resource in this case it is getting the images from the assets folder
            Uri uri;
            int score;

            if (clickedSong.Selected)
            {
                uri   = new Uri("ms-appx:///Assets/correct.png");
                score = (int)MyProgressBar.Value;
            }
            else
            {
                uri   = new Uri("ms-appx:///Assets/incorrect.png");
                score = ((int)MyProgressBar.Value) * -1;
            }
            StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(uri);

            var fileStream = await file.OpenAsync(FileAccessMode.Read);

            await clickedSong.AlbumCover.SetSourceAsync(fileStream);


            totalScore += score;
            round++;
            //Output of scores , Correct song, Album and so on...
            ResultTextBlock.Text = string.Format("Score: {0} Total Score after {1} Rounds: {2}", score, round, totalScore);
            TitleTextBlock.Text  = String.Format("Correct Song: {0}", correctSong.Title);
            ArtistTextBlock.Text = string.Format("Performed by: {0}", correctSong.Artist);
            AlbumTextBlock.Text  = string.Format("On Album: {0}", correctSong.Album);

            clickedSong.Used = true;

            correctSong.Selected = false;
            correctSong.Used     = true;

            if (round >= 5)
            {
                //Once game is over it will produce this message
                //Play Again button will also appear
                InstructionTextBlock.Text  = string.Format("Game over ... You scored: {0}", totalScore);
                PlayAgainButton.Visibility = Visibility.Visible;
            }
            else
            {
                StartCooldown();
            }
        }
Esempio n. 17
0
 private void Stop_Button_Click(object sender, RoutedEventArgs e)
 {
     MyMediaElement.Stop();
     filesPlaying = false;
 }
Esempio n. 18
0
 private void Button_Click_2(object sender, RoutedEventArgs e)
 {
     MyMediaElement.Stop();
 }