private void ChangePlayState(bool value) { if (value) { Artist = CurrentTrack.Artist; Song = CurrentTrack.Title; SelectedTrack.IsPlaying = true; MyMediaElement.Play(); _timer.Start(); foreach (var track in TrackModelList) { track.IsPlaying = track == CurrentTrack; track.IsPaused = false; } } else { MyMediaElement.Pause(); _timer.Stop(); foreach (var track in TrackModelList) { track.IsPlaying = false; if (track == CurrentTrack) { track.IsPaused = true; } } } }
private async void systemMediaControls_PropertyChanged(SystemMediaTransportControls sender, SystemMediaTransportControlsPropertyChangedEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (args.Property == SystemMediaTransportControlsProperty.SoundLevel) { // Check for the new Sound level switch (systemMediaControls.SoundLevel) { case SoundLevel.Full: if (pausedDueToMute) { // If we previously paused due to being muted, resume. MyMediaElement.Play(); } break; case SoundLevel.Low: // We're being ducked, take no action. break; case SoundLevel.Muted: if (MyMediaElement != null && MyMediaElement.CurrentState == MediaElementState.Playing) { // We've been muted by the system, pause to save our playback position. MyMediaElement.Pause(); pausedDueToMute = true; } break; } } }); }
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. } } }); }
private void btnPause_Click(object sender, RoutedEventArgs e) { if (isPlaying) { MyMediaElement.Pause(); isPlaying = true; //musicPlays = MusicPlays.Pause; btnPause.IsEnabled = false; btnPlay.IsEnabled = true; btnStop.IsEnabled = true; } }
void Play(object sender, RoutedEventArgs args) { ToggleButton tb = (ToggleButton)sender; if ((bool)tb.IsChecked) { MyMediaElement.Play(); } else { MyMediaElement.Pause(); } }
private void Play(object sender, RoutedEventArgs e) { if (running) { MyMediaElement.Pause(); PlayAndPauseButton.Icon = new SymbolIcon(Symbol.Play); running = false; } else { MyMediaElement.Play(); PlayAndPauseButton.Icon = new SymbolIcon(Symbol.Pause); running = true; } }
void Play(object sender, RoutedEventArgs e) { ToggleButton tb = (ToggleButton)sender; if ((bool)tb.IsChecked) { MyMediaElement.Play(); filesPlaying = true; } else { MyMediaElement.Pause(); filesPlaying = false; } }
private void PlayButton_Click(object sender, RoutedEventArgs e) { if (MyMediaElement.CurrentState == MediaElementState.Playing) { Symbol pico = Symbol.Play; SymbolIcon spico = new SymbolIcon(pico); Play.Icon = spico; MyMediaElement.Pause(); } else { Symbol pico = Symbol.Pause; SymbolIcon spico = new SymbolIcon(pico); Play.Icon = spico; MyMediaElement.Play(); } }
private void Play(object sender, RoutedEventArgs e) { if (running) { MyMediaElement.Pause(); PlayAndPauseButton.Symbol = Symbol.Play; running = false; timelineSlider.Value = timelineSlider.Value; } else { MyMediaElement.Play(); PlayAndPauseButton.Symbol = Symbol.Pause; running = true; timelineSlider.Value = timelineSlider.Value; } }
public void PauseSong(Song s) { IsPlay = false; PlayOrPause.Content = new Image { Source = new BitmapImage(new Uri(MediaPath.Play)) }; PlayOrPause.ToolTip = "Pause"; MyMediaElement.Pause(); if (Indicator == MediaCodes.PlayAudio) { GideonBase.SynObj.SpeakAsync("Song Paused!"); } else if (Indicator == MediaCodes.PlayVideo) { GideonBase.SynObj.SpeakAsync("Video Paused!"); } s.SongName = songname; }
private void PauseButton_Click(object sender, RoutedEventArgs e) { MyMediaElement.Pause(); }
private void SoundGridView_ItemClick(object sender, ItemClickEventArgs e) { if (!_playingMusic) { return; } CountDown.Pause(); MyMediaElement.Pause(); //Get the selected song var clickedSong = (Song)e.ClickedItem; var correctSong = Songs.FirstOrDefault(p => p.Id == _selectedSongPosition); int score; String scorePrefix; String titlePrefix; SolidColorBrush brushScore; SolidColorBrush brushTotal; if (clickedSong == correctSong) { score = (int)MyProgressBar.Value; scorePrefix = "You were correct"; titlePrefix = ""; brushScore = new SolidColorBrush(Colors.Green); } else { score = (int)MyProgressBar.Value * -1; if (score < 0 && score > -100) { score = -100 - score; } else if (score == -100) { score = -10; } scorePrefix = "Ooops! You missed this one..."; titlePrefix = "Correct Song : "; brushScore = new SolidColorBrush(Colors.Red); } Songs.Remove(correctSong); _round++; _totalScore += score; if (_totalScore >= 0) { brushTotal = new SolidColorBrush(Colors.DarkGreen); } else { brushTotal = new SolidColorBrush(Colors.DarkRed); } TotalScoreTextBlock.Text = String.Format("Total Score after {0} rounds is {1}", _round, _totalScore); TotalScoreTextBlock.Foreground = brushTotal; ScoreTextBlock.Text = String.Format("{0} .. Score : {1}", scorePrefix, score); ScoreTextBlock.Foreground = brushScore; TitleTextBlock.Text = String.Format("{0}{1}", titlePrefix, correctSong.Title); ArtistTextBlock.Text = String.Format("Performed By : {0}", correctSong.Artist); AlbumTextBlock.Text = String.Format("On Album : {0}", correctSong.Album); CorrectSongAlbumView.Source = correctSong.AlbumCover; if (_round == 10) { GameOver(); } else { StartCooldown(); } }