private async void Connection_ErrorOccurred(CastingConnection sender, CastingConnectionErrorOccurredEventArgs args)
        {
            if (args.ErrorStatus != CastingConnectionErrorStatus.Succeeded)
            {
                try
                {
                    sender.StateChanged  -= Connection_StateChanged;
                    sender.ErrorOccurred -= Connection_ErrorOccurred;
                }
                catch (Exception)
                {
                    //We already unhooked.
                }

                await sender.DisconnectAsync();

                sender.Dispose();
                MediaCastingConnection = null;

                //IsPlaying = false;

                //ShutdownPreviousPlaybackSession();

                await NepApp.UI.ShowInfoDialogAsync("Uh-Oh!", "An error occurred while casting: " + args.Message);

                if (!await App.GetIfPrimaryWindowVisibleAsync())
                {
                    var currentStation = await NepApp.Stations.GetStationByNameAsync(CurrentStream.ParentStation);

                    NepApp.UI.Notifier.ShowErrorToastNotification(currentStation, "Uh-Oh!", "An error occurred while casting: " + args.Message);
                }
            }
        }
Beispiel #2
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            player.Pause();
            InitialCastingPicker();
            if (connection == null)
            {
                // 從按下的 button 出現 picker 内容
                Button           btn       = sender as Button;
                GeneralTransform transform = btn.TransformToVisual(Window.Current.Content as UIElement);
                Point            pt        = transform.TransformPoint(new Point(0, 0));
                picker.Show(new Rect(pt.X, pt.Y, btn.ActualWidth, btn.ActualHeight), Windows.UI.Popups.Placement.Above);
            }
            else
            {
                // 關掉現在的連綫,要記得去掉 event 注冊以免發生 memory leak
                connection.ErrorOccurred -= Connection_ErrorOccurred;
                connection.StateChanged  -= Connection_StateChanged;
                await connection.DisconnectAsync();

                connection.Dispose();
                connection = null;
            }
        }