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 { } }); }
public OnlinePlayerView() { InitializeComponent(); m_ViewModel = new OnlinePlayerViewModel(new AnalyticsService(), StorageService.Current(), ApiService.Current()) { ChangeVolumeHandler = ChangeVolumeHandler, ChangePlayback = ChangePlaybackHandler, ChangePosition = ChangePosition, ScrollToSelectedPlaylist = ScrollToSelectedItemInPlaylist, SetVisiblePlaybackButtons = SetVisiblePlaybackButtons, ChangeOpenPlaylistButton = ChangeOpenPlaylistButton }; DataContext = m_ViewModel; OnlinePlayer.MediaPlayer.MediaOpened += MediaPlayer_MediaOpened; OnlinePlayer.MediaPlayer.MediaFailed += MediaPlayer_MediaFailed; OnlinePlayer.MediaPlayer.MediaEnded += MediaPlayer_MediaEnded; OnlinePlayer.MediaPlayer.SourceChanged += MediaPlayer_SourceChanged; OnlinePlayer.MediaPlayer.BufferingStarted += MediaPlayer_BufferingStarted; OnlinePlayer.MediaPlayer.BufferingEnded += MediaPlayer_BufferingEnded; OnlinePlayer.MediaPlayer.CurrentStateChanged += MediaPlayer_CurrentStateChanged; OnlinePlayer.MediaPlayer.VolumeChanged += MediaPlayer_VolumeChanged; OnlinePlayer.TransportControls.IsFastForwardButtonVisible = true; OnlinePlayer.TransportControls.IsFastForwardEnabled = true; OnlinePlayer.TransportControls.IsFastRewindButtonVisible = true; OnlinePlayer.TransportControls.IsFastRewindEnabled = true; //OnlinePlayer.TransportControls.IsPlaybackRateButtonVisible = true; //OnlinePlayer.TransportControls.IsPlaybackRateEnabled = true; OnlinePlayer.TransportControls.IsSkipBackwardButtonVisible = true; OnlinePlayer.TransportControls.IsSkipBackwardEnabled = true; OnlinePlayer.TransportControls.IsSkipForwardButtonVisible = true; OnlinePlayer.TransportControls.IsSkipForwardEnabled = true; OnlinePlayer.TransportControls.IsZoomButtonVisible = true; OnlinePlayer.TransportControls.IsZoomEnabled = true; OnlinePlayer.TransportControls.IsFullWindowEnabled = false; OnlinePlayer.TransportControls.IsFullWindowButtonVisible = false; RunTimer(); Loaded += OnlinePlayerView_Loaded; Unloaded += OnlinePlayerView_Unloaded; if (SystemService.GetDeviceFamilyType() != DeviceFamilyType.Xbox) { castingPicker = new CastingDevicePicker(); castingPicker.Filter.SupportsVideo = true; castingPicker.Filter.SupportedCastingSources.Add(OnlinePlayer.MediaPlayer.GetAsCastingSource()); castingPicker.CastingDeviceSelected += CastingPicker_CastingDeviceSelected; } else { m_GamepadTimer = new DispatcherTimer(); m_GamepadTimer.Tick += GamepadTimer_Tick; m_GamepadTimer.Start(); m_isXbox = true; m_ViewModel.IsXbox = true; } Window.Current.CoreWindow.KeyUp += GlobalKeyUpHandler; Window.Current.CoreWindow.PointerMoved += CoreWindow_PointerMoved; }
private void InitialCastingPicker() { if (picker == null) { picker = new CastingDevicePicker(); // 利用 MediaElement 的内容建立 filter picker.Filter.SupportedCastingSources.Add(player.GetAsCastingSource()); // 注冊處理選擇設備的事件 picker.CastingDeviceSelected += Picker_CastingDeviceSelected; // 注冊處理用戶沒有選擇設備的事件 picker.CastingDevicePickerDismissed += Picker_CastingDevicePickerDismissed; // 設定 picker 要顯示的畫面内容 picker.Appearance.BackgroundColor = Colors.Black; picker.Appearance.ForegroundColor = Colors.White; picker.Appearance.AccentColor = Colors.Gray; picker.Appearance.SelectedAccentColor = Colors.Gray; picker.Appearance.SelectedForegroundColor = Colors.White; picker.Appearance.SelectedBackgroundColor = Colors.Black; } }
private void InitialCastingPicker() { if (picker == null) { picker = new CastingDevicePicker(); // 利用 MediaElement 的内容建立 filter picker.Filter.SupportedCastingSources.Add(player.GetAsCastingSource()); // 注冊處理選擇設備的事件 picker.CastingDeviceSelected += Picker_CastingDeviceSelected; // 注冊處理用戶沒有選擇設備的事件 picker.CastingDevicePickerDismissed += Picker_CastingDevicePickerDismissed; // 設定 picker 要顯示的畫面内容 picker.Appearance.BackgroundColor = Colors.Black; picker.Appearance.ForegroundColor = Colors.White; picker.Appearance.AccentColor = Colors.Gray; picker.Appearance.SelectedAccentColor = Colors.Gray; picker.Appearance.SelectedForegroundColor = Colors.White; picker.Appearance.SelectedBackgroundColor = Colors.Black; } }
private async void Picker_CastingDevicePickerDismissed(CastingDevicePicker sender, object args) { // This dispatches the casting calls to the UI thread. await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { player.Play(); }); }
private async void Picker_CastingDevicePickerDismissed(CastingDevicePicker sender, object args) { // 要使用 UI Thread 控制當用戶沒有選擇設備時候要繼續播放 await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { player.Play(); }); }
public void Dispose() { player.PositionUpdated -= Player_PositionUpdated; player.StatusChanged -= Player_StatusChanged; dataTransferManager.DataRequested -= DataTransferManager_DataRequested; castingPicker.CastingDeviceSelected -= CastingPicker_CastingDeviceSelected; castingPicker = 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 void CustomMediaTransportControls_CastButton_Clicked(object sender, EventArgs e) { MenuFlyoutItem castButton = sender as MenuFlyoutItem; GeneralTransform transform = castButton.TransformToVisual(Window.Current.Content as UIElement); Point pt = transform.TransformPoint(new Point(0, 0)); CastingDevicePicker castingPicker = new CastingDevicePicker(); castingPicker.CastingDeviceSelected += CastingPicker_CastingDeviceSelected; castingPicker.Show(new Rect(pt.X, pt.Y, castButton.ActualWidth, castButton.ActualHeight)); }
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); }); }
public void ShowCastingPicker() { if (CurrentPlayer == null) { return; } CastingDevicePicker picker = new CastingDevicePicker(); picker.CastingDeviceSelected += Picker_CastingDeviceSelected; picker.CastingDevicePickerDismissed += Picker_CastingDevicePickerDismissed; picker.Show(Window.Current.Bounds); }
public Scenario2() { this.InitializeComponent(); //Initialize our picker object picker = new CastingDevicePicker(); //Set the picker to filter to video capable casting devices picker.Filter.SupportsVideo = true; //Hook up device selected event picker.CastingDeviceSelected += Picker_CastingDeviceSelected; }
public Scenario2() { this.InitializeComponent(); //Initialize our picker object picker = new CastingDevicePicker(); //Set the picker to filter to video capable casting devices picker.Filter.SupportsVideo = true; //Hook up device selected event picker.CastingDeviceSelected += Picker_CastingDeviceSelected; }
private void Picker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { sender.CastingDevicePickerDismissed -= Picker_CastingDevicePickerDismissed; sender.CastingDeviceSelected -= Picker_CastingDeviceSelected; App.Dispatcher.RunWhenIdleAsync(async() => { MediaCastingConnection = args.SelectedCastingDevice.CreateCastingConnection(); MediaCastingConnection.StateChanged += Connection_StateChanged; MediaCastingConnection.ErrorOccurred += Connection_ErrorOccurred; await MediaCastingConnection.RequestStartCastingAsync(CurrentPlayer.GetAsCastingSource()); }); }
public MainPage() { this.InitializeComponent(); // <SnippetInitCastingPicker> //Initialize our picker object castingPicker = new CastingDevicePicker(); //Set the picker to filter to video capable casting devices castingPicker.Filter.SupportsVideo = true; //Hook up device selected event castingPicker.CastingDeviceSelected += CastingPicker_CastingDeviceSelected; // </SnippetInitCastingPicker> }
private async void CastingPicker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { await Dispatcher.RunAsync( CoreDispatcherPriority.Normal, async() => { var connection = args.SelectedCastingDevice.CreateCastingConnection(); //Hook up the casting events //connection.ErrorOccurred += Connection_ErrorOccurred; //connection.StateChanged += Connection_StateChanged; var videoSource = OnlinePlayer.MediaPlayer.GetAsCastingSource(); await connection.RequestStartCastingAsync(videoSource); } ); }
// </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 Picker_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(video.GetAsCastingSource()); }); }
public Scenario02() { this.InitializeComponent(); rootPage = MainPage.Current; //Subscribe to player events player.MediaOpened += Player_MediaOpened; player.MediaFailed += Player_MediaFailed; player.CurrentStateChanged += Player_CurrentStateChanged; // Get an Azure hosted video AzureDataProvider dataProvider = new AzureDataProvider(); video = dataProvider.GetRandomVideo(); //Set the source on the player rootPage.NotifyUser(string.Format("Opening '{0}'", video.Title), NotifyType.StatusMessage); player.Source = video.VideoLink; this.LicenseText.Text = "License: " + video.License; //Subscribe for the clicked event on the custom cast button ((MediaTransportControlsWithCustomCastButton)this.player.TransportControls).CastButtonClicked += TransportControls_CastButtonClicked; // Instantiate the Device Picker picker = new CastingDevicePicker(); // Generate the filter based on the content in the MediaElement picker.Filter.SupportedCastingSources.Add(player.GetAsCastingSource()); //Hook up device selected event picker.CastingDeviceSelected += Picker_CastingDeviceSelected; //Hook up device disconnected event picker.CastingDevicePickerDismissed += Picker_CastingDevicePickerDismissed; //Set the Appearence of the picker picker.Appearance.BackgroundColor = Colors.Black; picker.Appearance.ForegroundColor = Colors.White; picker.Appearance.AccentColor = Colors.Gray; picker.Appearance.SelectedAccentColor = Colors.Gray; picker.Appearance.SelectedForegroundColor = Colors.White; picker.Appearance.SelectedBackgroundColor = Colors.Black; }
public Scenario02() { this.InitializeComponent(); rootPage = MainPage.Current; //Subscribe to player events player.MediaOpened += Player_MediaOpened; player.MediaFailed += Player_MediaFailed; player.CurrentStateChanged += Player_CurrentStateChanged; // Get an Azure hosted video AzureDataProvider dataProvider = new AzureDataProvider(); video = dataProvider.GetRandomVideo(); //Set the source on the player rootPage.NotifyUser(string.Format("Opening '{0}'", video.Title), NotifyType.StatusMessage); player.Source = video.VideoLink; this.LicenseText.Text = "License: " + video.License; //Subscribe for the clicked event on the custom cast button ((MediaTransportControlsWithCustomCastButton)this.player.TransportControls).CastButtonClicked += TransportControls_CastButtonClicked; // Instantiate the Device Picker picker = new CastingDevicePicker(); // Generate the filter based on the content in the MediaElement picker.Filter.SupportedCastingSources.Add(player.GetAsCastingSource()); //Hook up device selected event picker.CastingDeviceSelected += Picker_CastingDeviceSelected; //Hook up device disconnected event picker.CastingDevicePickerDismissed += Picker_CastingDevicePickerDismissed; //Set the Appearence of the picker picker.Appearance.BackgroundColor = Colors.Black; picker.Appearance.ForegroundColor = Colors.White; picker.Appearance.AccentColor = Colors.Gray; picker.Appearance.SelectedAccentColor = Colors.Gray; picker.Appearance.SelectedForegroundColor = Colors.White; picker.Appearance.SelectedBackgroundColor = Colors.Black; }
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); } }); }
public Live() { this.InitializeComponent(); player.MediaOpened += Player_MediaOpened; player.MediaFailed += Player_MediaFailed; player.CurrentStateChanged += Player_CurrentStateChanged; // Get an Azure hosted video VideoDataProvider dataProvider = new VideoDataProvider(); video = dataProvider.GetRandomVideo(); //Set the source on the player player.Source = video.VideoLink; //Subscribe for the clicked event on the custom cast button ((MediaTransportControlsWithCustomCastButton)this.player.TransportControls).CastButtonClicked += TransportControls_CastButtonClicked; // Instantiate the Device Picker picker = new CastingDevicePicker(); // Generate the filter based on the content in the MediaElement picker.Filter.SupportedCastingSources.Add(player.GetAsCastingSource()); //Hook up device selected event picker.CastingDeviceSelected += Picker_CastingDeviceSelected; //Hook up device disconnected event picker.CastingDevicePickerDismissed += Picker_CastingDevicePickerDismissed; //Set the Appearence of the picker picker.Appearance.BackgroundColor = Colors.Black; picker.Appearance.ForegroundColor = Colors.White; picker.Appearance.AccentColor = Colors.Gray; picker.Appearance.SelectedAccentColor = Colors.Gray; picker.Appearance.SelectedForegroundColor = Colors.White; picker.Appearance.SelectedBackgroundColor = Colors.Black; }
public Shell() { InitializeComponent(); GlobalStateManager.CurrentShell = this; //Wait Ring WaitRingManager.OnGetWaitRingRequired = OnGetWaitRingRequired; WaitRingManager.OnSetWaitRingRequired = OnSetWaitRingRequired; WaitRingManager.OnShowBlurBackgroundRequired = ShowBlurBackground; // Navigation GlobalStateManager.OnSelectedMenuIndexChanged = OnSelectedMenuIndexChanged; GlobalStateManager.OnGetSelectedMenuIndexRequired = OnGetSelectedMenuIndexRequired; if (CoreTools.IsRunningOnMobile) { DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait | DisplayOrientations.PortraitFlipped; } MediaPlayerHost.Attach(mediaPlayerElement); try { if (ApiInformation.IsTypePresent("Windows.Media.Casting.CastingDevicePicker")) { castingPicker = new CastingDevicePicker(); castingPicker.Filter.SupportsVideo = true; castingPicker.Filter.SupportsAudio = true; castingPicker.CastingDeviceSelected += CastingPicker_CastingDeviceSelected; } } catch { // Picker not available. Hololens for instance Cast.IsEnabled = false; } }
public CastingDevicePickerEvents(CastingDevicePicker This) { this.This = This; }
private async void Picker_CastingDevicePickerDismissed(CastingDevicePicker sender, object args) { // This dispatches the casting calls to the UI thread. await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { player.Play(); }); }
private void Picker_CastingDevicePickerDismissed(CastingDevicePicker sender, object args) { sender.CastingDevicePickerDismissed -= Picker_CastingDevicePickerDismissed; sender.CastingDeviceSelected -= Picker_CastingDeviceSelected; }
private async void CastingPicker_CastingDeviceSelected(CastingDevicePicker sender, CastingDeviceSelectedEventArgs args) { CastingConnection connection = args.SelectedCastingDevice.CreateCastingConnection(); await connection.RequestStartCastingAsync(PlayingSound.MediaPlayer.GetAsCastingSource()); }
public async void Init(SongViewModel song) { //Initialize our picker object castingPicker = new CastingDevicePicker(); //Set the picker to filter to video capable casting devices castingPicker.Filter.SupportsAudio = true; //Hook up device selected event castingPicker.CastingDeviceSelected += CastingPicker_CastingDeviceSelected; Song = song; _lastSong = new Song() { ID = song.ID, IsOnline = song.IsOnline, OnlineUri = new Uri(song.FilePath), FilePath = song.FilePath, Duration = song.Song.Duration, Album = song.Album, OnlineAlbumID = song.Song.OnlineAlbumID, OnlineID = song.Song.OnlineID }; CurrentArtwork = song.Artwork; lastUriPath = song.Artwork?.AbsolutePath; IsPlaying = player.IsPlaying; BufferProgress = MainPageViewModel.Current.BufferProgress; SongChanged?.Invoke(song, EventArgs.Empty); CurrentRating = song.Rating; var brush = new SolidColorBrush(await ImagingHelper.GetMainColor(CurrentArtwork)); CurrentColorBrush = brush; MainPageViewModel.Current.LeftTopColor = AdjustColorbyTheme(CurrentColorBrush); CurrentIndex = MainPageViewModel.Current.CurrentIndex; var task = ThreadPool.RunAsync(async x => { var favor = await _lastSong.GetFavoriteAsync(); await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { IsCurrentFavorite = favor; }); }); var t = ThreadPool.RunAsync(async x => { var ext = MainPageViewModel.Current.LyricExtension; if (ext != null) { var result = await ext.ExecuteAsync(new ValueSet() { new KeyValuePair <string, object>("q", "lyric"), new KeyValuePair <string, object>("title", Song.Title), new KeyValuePair <string, object>("album", song.Album), new KeyValuePair <string, object>("artist", Song.Song.Performers.IsNullorEmpty() ? null : Song.Song.Performers[0]), new KeyValuePair <string, object>("ID", song.IsOnline ? song.Song.OnlineID : null) }); if (result != null) { var l = new Lyric(LrcParser.Parser.Parse((string)result, Song.Song.Duration)); await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => { Lyric.New(l); }); } else { await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => { Lyric.Clear(); LyricHint = Consts.Localizer.GetString("NoLyricText"); }); } } else { await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () => { Lyric.Clear(); LyricHint = Consts.Localizer.GetString("NoLyricText"); }); } }); }
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 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); } }); }
private async void Picker_CastingDevicePickerDismissed(CastingDevicePicker sender, object args) { // 要使用 UI Thread 控制當用戶沒有選擇設備時候要繼續播放 await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { player.Play(); }); }