private async void Connection_ErrorOccurred(CastingConnection sender, CastingConnectionErrorOccurredEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { // handle CastingConnectionErrorStatus }); }
private async void Picker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { connection = args.SelectedCastingDevice.CreateCastingConnection(); //Hook up the casting events connection.ErrorOccurred += Connection_ErrorOccurred; connection.StateChanged += Connection_StateChanged; // Get the casting source from the MediaElement CastingSource source = null; try { // Get the casting source from the Media Element source = player.GetAsCastingSource(); // Start Casting CastingConnectionErrorStatus status = await connection.RequestStartCastingAsync(source); if (status == CastingConnectionErrorStatus.Succeeded) { player.Play(); } } catch { } }); }
// </SnippetSelectionChanged> // <SnippetStateChanged> private async void Connection_StateChanged(CastingConnection sender, object args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { //Update the UX based on the casting state if (sender.State == CastingConnectionState.Connected || sender.State == CastingConnectionState.Rendering) { disconnectButton.Visibility = Visibility.Visible; watcherProgressRing.IsActive = false; } else if (sender.State == CastingConnectionState.Disconnected) { disconnectButton.Visibility = Visibility.Collapsed; castingDevicesListBox.SelectedItem = null; watcherProgressRing.IsActive = false; } else if (sender.State == CastingConnectionState.Connecting) { disconnectButton.Visibility = Visibility.Collapsed; ShowMessageToUser("Connecting"); watcherProgressRing.IsActive = true; } else { //Disconnecting is the remaining state disconnectButton.Visibility = Visibility.Collapsed; watcherProgressRing.IsActive = true; } }); }
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); } } }
private void Connection_StateChanged(CastingConnection sender, object args) { switch (sender.State) { case CastingConnectionState.Connected: case CastingConnectionState.Connecting: case CastingConnectionState.Rendering: SetIsCasting(true); break; default: SetIsCasting(false); try { sender.StateChanged -= Connection_StateChanged; sender.ErrorOccurred -= Connection_ErrorOccurred; } catch (Exception) { //We already unhooked. } break; } }
private async Task CastingVideoToScreen(DevicePicker sender, DeviceSelectedEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { activeDevice = args.SelectedDevice; CastingDevice device = await CastingDevice.FromIdAsync(args.SelectedDevice.Id); castingConnection = device.CreateCastingConnection(); //Hook up the casting events //castingConnection.ErrorOccurred += Connection_ErrorOccurred; //castingConnection.StateChanged += Connection_StateChanged; // Get the casting source from the MediaElement CastingSource source = null; try { // Get the casting source from the Media Element source = player.GetAsCastingSource(); // Start Casting CastingConnectionErrorStatus status = await castingConnection.RequestStartCastingAsync(source); if (status == CastingConnectionErrorStatus.Succeeded) { player.Play(); } } catch { } }); }
private async void Connection_StateChanged(CastingConnection sender, object args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("Casting Connection State Changed: " + sender.State, NotifyType.StatusMessage); }); }
private async void Connection_ErrorOccurred(CastingConnection sender, CastingConnectionErrorOccurredEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("Connection Error Occured: " + args.Message, NotifyType.ErrorMessage); }); }
private async void Connection_StateChanged(CastingConnection sender, object args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { disconnectButton.IsEnabled = !(sender.State == CastingConnectionState.Disconnected || sender.State == CastingConnectionState.Disconnecting); rootPage.NotifyUser("Casting Connection State Changed: " + sender.State, NotifyType.StatusMessage); }); }
// </SnippetStateChanged> // <SnippetErrorOccurred> private async void Connection_ErrorOccurred(CastingConnection sender, CastingConnectionErrorOccurredEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { //Clear the selection in the listbox on an error ShowMessageToUser("Casting Error: " + args.Message); castingDevicesListBox.SelectedItem = null; }); }
private async void Connection_ErrorOccurred(CastingConnection sender, CastingConnectionErrorOccurredEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("Casting Error Occured: " + args.Message, NotifyType.ErrorMessage); disconnectButton.IsEnabled = false; activeDevice = null; activeCastConnectionHandler = null; }); }
private async void Picker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { try { //rootPage.NotifyUser(string.Format("Picker DeviceSelected event fired for device '{0}'", args.SelectedCastingDevice.FriendlyName), NotifyType.StatusMessage); DateTime t1 = DateTime.Now; DeviceInformation mydevice = await DeviceInformation.CreateFromIdAsync(args.SelectedCastingDevice.Id); DateTime t2 = DateTime.Now; TimeSpan ts = new TimeSpan(t2.Ticks - t1.Ticks); //System.Diagnostics.Debug.WriteLine(string.Format("DeviceInformation.CreateFromIdAsync took '{0} seconds'", ts.TotalSeconds)); //Create a casting conneciton from our selected casting device //rootPage.NotifyUser(string.Format("Creating connection for '{0}'", args.SelectedCastingDevice.FriendlyName), NotifyType.StatusMessage); connection = args.SelectedCastingDevice.CreateCastingConnection(); //Hook up the casting events connection.ErrorOccurred += Connection_ErrorOccurred; connection.StateChanged += Connection_StateChanged; // Get the casting source from the MediaElement CastingSource source = null; try { // Get the casting source from the Media Element source = player.GetAsCastingSource(); // Start Casting //rootPage.NotifyUser(string.Format("Starting casting to '{0}'", args.SelectedCastingDevice.FriendlyName), NotifyType.StatusMessage); CastingConnectionErrorStatus status = await connection.RequestStartCastingAsync(source); if (status == CastingConnectionErrorStatus.Succeeded) { player.Play(); //rootPage.NotifyUser(string.Format("Starting casting to '{0}'", args.SelectedCastingDevice.FriendlyName), NotifyType.StatusMessage); } } catch { //rootPage.NotifyUser(string.Format("Failed to get casting source for video '{0}'", video.Title), NotifyType.ErrorMessage); } } catch (Exception ex) { #if DEBUG System.Diagnostics.Debug.WriteLine(ex.Message); #endif } }); }
private async void CastingPicker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { //Casting must occur from the UI thread. This dispatches the casting calls to the UI thread. await DispatchManager.RunOnDispatcherAsync(async() => { //Create a casting connection from our selected casting device CastingConnection connection = args.SelectedCastingDevice.CreateCastingConnection(); //Cast the content loaded in the media element to the selected casting device await connection.RequestStartCastingAsync(MediaPlayerHost.CastingSource); }); }
private async void OnCastingError(CastingConnection sender, CastingConnectionErrorOccurredEventArgs args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { LoadingBar.Visibility = Visibility.Collapsed; LoadingPane.Visibility = Visibility.Visible; LoadingTitle.Text = "Error"; LoadingText.Text = args.Message; LoadingCancelButton.Visibility = Visibility.Visible; LoadingCancelButton.Content = "Close"; }); }
private async void Connection_StateChanged(CastingConnection sender, object args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { if (sender.State == CastingConnectionState.Connected || sender.State == CastingConnectionState.Rendering) { castingIcon.Foreground = new SolidColorBrush(Colors.Red); } else { castingIcon.Foreground = new SolidColorBrush(Colors.DimGray); } }); }
// </SnippetCastPickerButtonClick> // <SnippetCastingDeviceSelected> private async void CastingPicker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { //Casting must occur from the UI thread. This dispatches the casting calls to the UI thread. await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { //Create a casting conneciton from our selected casting device CastingConnection connection = args.SelectedCastingDevice.CreateCastingConnection(); //Hook up the casting events connection.ErrorOccurred += Connection_ErrorOccurred; connection.StateChanged += Connection_StateChanged; //Cast the content loaded in the media element to the selected casting device await connection.RequestStartCastingAsync(mediaElement.GetAsCastingSource()); }); }
private async void CastToDevice(object sender, Windows.UI.Xaml.Controls.ItemClickEventArgs e) { // Ensure we stop looking for devices before casting if (_deviceWatcher.Status != DeviceWatcherStatus.Stopped) { _deviceWatcher.Stop(); } // Create the connection _castingConnection = (e.ClickedItem as CastingDevice).CreateCastingConnection(); // Bind events _castingConnection.ErrorOccurred += OnCastingError; _castingConnection.StateChanged += OnCastingStateChange; await _castingConnection.RequestStartCastingAsync(SimpleIoc.Default.GetInstance <IPlaybackService>().GetMediaPlayer().GetAsCastingSource()); }
private async Task <bool> TryDisconnectCastingSessionAsync(CastingConnection connection) { bool disconnected = false; //Disconnect the casting session CastingConnectionErrorStatus status = await connection.DisconnectAsync(); if (status == CastingConnectionErrorStatus.Succeeded) { rootPage.NotifyUser("Connection disconnected successfully.", NotifyType.StatusMessage); disconnected = true; } else { rootPage.NotifyUser(string.Format("Failed to disconnect connection with reason {0}.", status.ToString()), NotifyType.ErrorMessage); } return(disconnected); }
private async void Picker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { // The args.SelectedCastingDevice is proxied from the picker process. The picker process is // dismissmed as soon as you break into the debugger. Creating a non-proxied version // allows debugging since the proxied version stops working once the picker is dismissed. CastingDevice selectedDevice = await CastingDevice.FromIdAsync(args.SelectedCastingDevice.Id); //Create a casting conneciton from our selected casting device rootPage.NotifyUser(string.Format("Creating connection for '{0}'", selectedDevice.FriendlyName), NotifyType.StatusMessage); CastingConnection connection = selectedDevice.CreateCastingConnection(); //Hook up the casting events connection.ErrorOccurred += Connection_ErrorOccurred; connection.StateChanged += Connection_StateChanged; // Get the casting source from the MediaElement CastingSource source = null; try { // Get the casting source from the Media Element source = player.GetAsCastingSource(); // Start Casting rootPage.NotifyUser(string.Format("Starting casting to '{0}'", selectedDevice.FriendlyName), NotifyType.StatusMessage); CastingConnectionErrorStatus status = await connection.RequestStartCastingAsync(source); if (status == CastingConnectionErrorStatus.Succeeded) { player.Play(); rootPage.NotifyUser(string.Format("Starting casting to '{0}'", selectedDevice.FriendlyName), NotifyType.StatusMessage); } } catch { rootPage.NotifyUser(string.Format("Failed to get casting source for video '{0}'", video.Title), NotifyType.ErrorMessage); } }); }
private async void OnCastingStateChange(CastingConnection sender, object args) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { switch (sender.State) { case CastingConnectionState.Disconnected: LoadingPane.Visibility = Visibility.Collapsed; break; case CastingConnectionState.Connected: case CastingConnectionState.Rendering: LoadingBar.Visibility = Visibility.Collapsed; LoadingPane.Visibility = Visibility.Visible; LoadingTitle.Text = "Casting..."; LoadingText.Text = "Casting music to your device."; LoadingCancelButton.Visibility = Visibility.Visible; LoadingCancelButton.Content = "Disconnect"; break; case CastingConnectionState.Disconnecting: LoadingBar.Visibility = Visibility.Visible; LoadingPane.Visibility = Visibility.Visible; LoadingTitle.Text = "Disconnecting..."; LoadingText.Text = "Trying to disconnect from the device."; LoadingCancelButton.Visibility = Visibility.Collapsed; break; case CastingConnectionState.Connecting: LoadingBar.Visibility = Visibility.Visible; LoadingPane.Visibility = Visibility.Visible; LoadingTitle.Text = "Connecting..."; LoadingText.Text = "Trying to connect to your selected device."; LoadingCancelButton.Visibility = Visibility.Visible; LoadingCancelButton.Content = "Cancel"; break; } }); }
private async void castingDevicesList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (castingDevicesList.SelectedItem != null) { //When a device is selected, first thing we do is stop the watcher so it's search doesn't conflict with streaming if (watcher.Status != DeviceWatcherStatus.Stopped) { progressText.Text = ""; watcher.Stop(); } //Create a new casting connection to the device that's been selected connection = ((CastingDevice)castingDevicesList.SelectedItem).CreateCastingConnection(); //Register for events connection.ErrorOccurred += Connection_ErrorOccurred; connection.StateChanged += Connection_StateChanged; //Cast the loaded video to the selected casting device. await connection.RequestStartCastingAsync(video.GetAsCastingSource()); } }
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; } }
// </SnippetWatcherStopped> // <SnippetSelectionChanged> private async void castingDevicesListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (castingDevicesListBox.SelectedItem != null) { //When a device is selected, first thing we do is stop the watcher so it's search doesn't conflict with streaming if (deviceWatcher.Status != DeviceWatcherStatus.Stopped) { deviceWatcher.Stop(); } //Create a new casting connection to the device that's been selected castingConnection = ((CastingDevice)castingDevicesListBox.SelectedItem).CreateCastingConnection(); //Register for events castingConnection.ErrorOccurred += Connection_ErrorOccurred; castingConnection.StateChanged += Connection_StateChanged; //Cast the loaded video to the selected casting device. await castingConnection.RequestStartCastingAsync(mediaPlayerElement.MediaPlayer.GetAsCastingSource()); disconnectButton.Visibility = Visibility.Visible; } }
private async void Connection_ErrorOccurred(CastingConnection sender, CastingConnectionErrorOccurredEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { //Clear the selection in the listbox on an error rootPage.NotifyUser("Casting Error: " + args.Message, NotifyType.ErrorMessage); castingDevicesList.SelectedItem = null; }); }
private async Task CastingVideoToScreen(DevicePicker sender, DeviceSelectedEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { activeDevice = args.SelectedDevice; CastingDevice device =await CastingDevice.FromIdAsync(args.SelectedDevice.Id); castingConnection = device.CreateCastingConnection(); //Hook up the casting events //castingConnection.ErrorOccurred += Connection_ErrorOccurred; //castingConnection.StateChanged += Connection_StateChanged; // Get the casting source from the MediaElement CastingSource source = null; try { // Get the casting source from the Media Element source = player.GetAsCastingSource(); // Start Casting CastingConnectionErrorStatus status = await castingConnection.RequestStartCastingAsync(source); if (status == CastingConnectionErrorStatus.Succeeded) { player.Play(); } } catch { } }); }
private async Task <bool> TryCastMediaElementAsync(DeviceInformation device) { bool castMediaElementSucceeded = false; //Verify whether the selected device supports DLNA, Bluetooth, or Miracast. rootPage.NotifyUser(string.Format("Checking to see if device {0} supports Miracast, Bluetooth, or DLNA", device.Name), NotifyType.StatusMessage); //BUG: Takes too long. Workaround, just try to create the CastingDevice //if (await CastingDevice.DeviceInfoSupportsCastingAsync(device)) //{ CastingConnection connection = null; //Check to see whether we are casting to the same device if (activeDevice != null && device.Id == activeDevice.Id) { connection = activeCastConnectionHandler as CastingConnection; } else // if not casting to the same device reset the active device related variables. { activeDevice = null; activeCastConnectionHandler = null; } // If we can re-use the existing connection if (connection == null || connection.State == CastingConnectionState.Disconnected || connection.State == CastingConnectionState.Disconnecting) { CastingDevice castDevice = null; activeDevice = null; //Try to create a CastingDevice instannce. If it doesn't succeed, the selected device does not support playback of the video source. rootPage.NotifyUser(string.Format("Attempting to resolve casting device for '{0}'", device.Name), NotifyType.StatusMessage); try { castDevice = await CastingDevice.FromIdAsync(device.Id); } catch { } if (castDevice == null) { //Try to create a DIAL device. If it doesn't succeed, the selected device does not support DIAL. rootPage.NotifyUser(string.Format("'{0}' does not support playback of this media", device.Name), NotifyType.StatusMessage); } else { //Create a casting conneciton from our selected casting device rootPage.NotifyUser(string.Format("Creating connection for '{0}'", device.Name), NotifyType.StatusMessage); connection = castDevice.CreateCastingConnection(); //Hook up the casting events connection.ErrorOccurred += Connection_ErrorOccurred; connection.StateChanged += Connection_StateChanged; } //Cast the content loaded in the media element to the selected casting device rootPage.NotifyUser(string.Format("Casting to '{0}'", device.Name), NotifyType.StatusMessage); CastingSource source = null; // Get the casting source try { source = player.GetAsCastingSource(); } catch { } if (source == null) { rootPage.NotifyUser(string.Format("Failed to get casting source for video '{0}'", video.Title), NotifyType.ErrorMessage); } else { CastingConnectionErrorStatus status = await connection.RequestStartCastingAsync(source); if (status == CastingConnectionErrorStatus.Succeeded) { //Remember the device to which casting succeeded activeDevice = device; //Remember the current active connection. activeCastConnectionHandler = connection; castMediaElementSucceeded = true; player.Play(); } else { rootPage.NotifyUser(string.Format("Failed to cast to '{0}'", device.Name), NotifyType.ErrorMessage); } } //} } return(castMediaElementSucceeded); }
private async void CastingPicker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { CastingConnection connection = args.SelectedCastingDevice.CreateCastingConnection(); await connection.RequestStartCastingAsync(PlayingSound.MediaPlayer.GetAsCastingSource()); }
private void Connection_StateChanged(CastingConnection sender, object args) { }
private void Connection_ErrorOccurred(CastingConnection sender, CastingConnectionErrorOccurredEventArgs args) { MainPage.Current.PopMessage($"Casting Error: {args.ErrorStatus.ToString()}\r\n{args.Message}"); }
private async void Connection_ErrorOccurred(CastingConnection sender, CastingConnectionErrorOccurredEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { rootPage.NotifyUser("Casting Error Occured: " + args.Message, NotifyType.ErrorMessage); }); }
private async void Connection_StateChanged(CastingConnection sender, object args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { //Update the UX based on the casting state if (sender.State == CastingConnectionState.Connected || sender.State == CastingConnectionState.Rendering) { disconnectButton.Visibility = Visibility.Visible; progressText.Text = "Connected"; progressRing.IsActive = false; } else if (sender.State == CastingConnectionState.Disconnected) { disconnectButton.Visibility = Visibility.Collapsed; castingDevicesList.SelectedItem = null; progressText.Text = ""; progressRing.IsActive = false; } else if (sender.State == CastingConnectionState.Connecting) { disconnectButton.Visibility = Visibility.Collapsed; progressText.Text = "Connecting"; progressRing.IsActive = true; } else { //Disconnecting is the remaining state disconnectButton.Visibility = Visibility.Collapsed; progressText.Text = "Disconnecting"; progressRing.IsActive = true; } }); }
private async void Picker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { connection = args.SelectedCastingDevice.CreateCastingConnection(); //Hook up the casting events connection.ErrorOccurred += Connection_ErrorOccurred; connection.StateChanged += Connection_StateChanged; // Get the casting source from the MediaElement CastingSource source = null; try { // Get the casting source from the Media Element source = player.GetAsCastingSource(); // Start Casting CastingConnectionErrorStatus status = await connection.RequestStartCastingAsync(source); if (status == CastingConnectionErrorStatus.Succeeded) { player.Play(); } } catch { } }); }
private async void Connection_StateChanged(CastingConnection sender, object args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { }); }
private async Task<bool> TryDisconnectCastingSessionAsync(CastingConnection connection) { bool disconnected = false; //Disconnect the casting session CastingConnectionErrorStatus status = await connection.DisconnectAsync(); if (status == CastingConnectionErrorStatus.Succeeded) { rootPage.NotifyUser("Connection disconnected successfully.", NotifyType.StatusMessage); disconnected = true; } else { rootPage.NotifyUser(string.Format("Failed to disconnect connection with reason {0}.", status.ToString()), NotifyType.ErrorMessage); } return disconnected; }
private async void Picker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { try { rootPage.NotifyUser(string.Format("Picker DeviceSelected event fired for device '{0}'", args.SelectedCastingDevice.FriendlyName), NotifyType.StatusMessage); //DateTime t1 = DateTime.Now; //DeviceInformation mydevice = await DeviceInformation.CreateFromIdAsync(args.SelectedCastingDevice.Id); //DateTime t2 = DateTime.Now; //TimeSpan ts = new TimeSpan(t2.Ticks - t1.Ticks); //System.Diagnostics.Debug.WriteLine(string.Format("DeviceInformation.CreateFromIdAsync took '{0} seconds'", ts.TotalSeconds)); //Create a casting conneciton from our selected casting device rootPage.NotifyUser(string.Format("Creating connection for '{0}'", args.SelectedCastingDevice.FriendlyName), NotifyType.StatusMessage); connection = args.SelectedCastingDevice.CreateCastingConnection(); //Hook up the casting events connection.ErrorOccurred += Connection_ErrorOccurred; connection.StateChanged += Connection_StateChanged; // Get the casting source from the MediaElement CastingSource source = null; try { // Get the casting source from the Media Element source = player.GetAsCastingSource(); // Start Casting rootPage.NotifyUser(string.Format("Starting casting to '{0}'", args.SelectedCastingDevice.FriendlyName), NotifyType.StatusMessage); CastingConnectionErrorStatus status = await connection.RequestStartCastingAsync(source); if (status == CastingConnectionErrorStatus.Succeeded) { player.Play(); rootPage.NotifyUser(string.Format("Starting casting to '{0}'", args.SelectedCastingDevice.FriendlyName), NotifyType.StatusMessage); } } catch { rootPage.NotifyUser(string.Format("Failed to get casting source for video '{0}'", video.Title), NotifyType.ErrorMessage); } } catch (Exception ex) { UnhandledExceptionPage.ShowUnhandledException(ex); } }); }
public CastingConnectionEvents(CastingConnection This) { this.This = This; }