private async void HandleStopReceiverClicked(Object sender, RoutedEventArgs e) { try { if (_receiver != null) { await _receiver.StopAsync(); // The DisplayRequest should be released as soon as it is not needed anymore if (_displayRequest != null) { _displayRequest.RequestRelease(); _displayRequest = null; } // Remove Play To Receiver events _receiver.SourceChangeRequested -= HandleReceiverSourceChangeRequested; _receiver.PlayRequested -= HandleReceiverPlayRequested; _receiver.PauseRequested -= HandleReceiverPauseRequested; _receiver.StopRequested -= HandleReceiverStopRequested; _receiver.PlaybackRateChangeRequested -= HandleReceiverPlaybackRateChangeRequested; _receiver.CurrentTimeChangeRequested -= HandleReceiverCurrentTimeChangeRequested; _receiver.TimeUpdateRequested -= HandleReceiverTimeUpdateRequested; _receiver.MuteChangeRequested -= HandleReceiverMuteChangeRequested; _receiver.VolumeChangeRequested -= HandleReceiverVolumeChangeRequested; // Remove MediaElement events VideoPlayer.Pause(); StatusText.Text = "Stopped '" + _receiver.FriendlyName + "'."; } } catch { var friendlyName = _receiver == null ? String.Empty : _receiver.FriendlyName; StatusText.Text = "Failed to stop '" + friendlyName + "'."; } }
/// <summary> /// This is the click handler for the 'Other' button. You would replace this with your own handler /// if you have a button or buttons on this page. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> async private void stopPlayToReceiver(object sender, RoutedEventArgs e) { Button b = sender as Button; if (b != null) { try { startDMRButton.IsEnabled = true; stopDMRButton.IsEnabled = false; await receiver.StopAsync(); IsReceiverStarted = false; rootPage.NotifyUser("PlayToReceiver stopped", NotifyType.StatusMessage); } catch (Exception ecp) { IsReceiverStarted = true; startDMRButton.IsEnabled = false; stopDMRButton.IsEnabled = true; rootPage.NotifyUser("PlayToReceiver stop failed, Error " + ecp.Message, NotifyType.ErrorMessage); } } }