private async void btnCast_Click(object sender, EventArgs e) { string url = txtURL.Text; btnCast.Enabled = false; if (url.Length < 10) { MessageBox.Show("Enter a valid URL"); btnCast.Enabled = true; return; } try { if (_chromecastService.ChromeCastClient.Connected) { await _chromecastService.ChromeCastClient.DisconnectChromecast(); } if (!_chromecastService.ChromeCastClient.Connected) { lblStatus.Text = $"Finding {selectedChromecast.FriendlyName} {selectedChromecast.DeviceUri}"; //relocated selected device? var devices = await ChromecastService.StartLocatingDevices(); if (devices.Count == 0) { System.Console.WriteLine("No chromecasts found"); return; } var firstChromecast = devices.Where(x => x.DeviceUri == selectedChromecast.DeviceUri).First(); //this will find the tv await ChromecastService.ConnectToChromecast(firstChromecast); lblStatus.Text = $"Connected to {firstChromecast.FriendlyName} {firstChromecast.DeviceUri}"; //await connect.ContinueWith(t => { // lblStatus.Text = "Connected?"; // Task openPage = OpenWebPage(url); // openPage.ContinueWith(x => // { // lblStatus.Text = "Web page opened?"; // btnCast.Enabled = true; // }); //}); } } catch (Exception ex) { MessageBox.Show(ex.Message); } btnCast.Enabled = true; }
public ChromecastTester() { _chromecastService = ChromecastService.Current; var device = _chromecastService.StartLocatingDevices().Result; _chromecastService.ConnectToChromecast(device.First()).Wait(2000); }
public async void c_Selected(object sender, EventArgs e) { var menuItem = (System.Windows.Forms.ToolStripMenuItem)sender; var device = menuItem.Tag as Chromecast; if (device != null) { if (menuItem.Checked) { menuItem.Checked = false; ChromecastService.ChromeCastClient.ConnectedChanged -= ChromeCastClient_Connected; ChromecastService.ChromeCastClient.ApplicationStarted -= Client_ApplicationStarted; await _controller.Stop(); await _controller.StopApplication(); //TODO: Disconnect from the chromecast. Dispose the socket connection //reference: https://github.com/tapanila/SharpCaster/blob/master/SharpCaster/ChromeCastClient.cs Line:191 } else { menuItem.Checked = true; ChromecastService.ChromeCastClient.ConnectedChanged += ChromeCastClient_Connected; ChromecastService.ChromeCastClient.ApplicationStarted += Client_ApplicationStarted; ChromecastService.ConnectToChromecast(device); } } }
private static async Task DoStuff() { ChromecastService.ChromeCastClient.ApplicationStarted += Client_ApplicationStarted; ChromecastService.ChromeCastClient.VolumeChanged += _client_VolumeChanged; ChromecastService.ChromeCastClient.MediaStatusChanged += ChromeCastClient_MediaStatusChanged; ChromecastService.ChromeCastClient.ConnectedChanged += ChromeCastClient_Connected; System.Console.WriteLine("Started locating chromecasts!"); var devices = await ChromecastService.StartLocatingDevices(); if (devices.Count == 0) { System.Console.WriteLine("No chromecasts found"); return; } var firstChromecast = devices.First(); System.Console.WriteLine("Device found " + firstChromecast.FriendlyName); ChromecastService.ConnectToChromecast(firstChromecast); }
private static async Task AsyncBabyAsyn() { ChromecastService.ChromeCastClient.ApplicationStarted += Client_ApplicationStarted; ChromecastService.ChromeCastClient.VolumeChanged += _client_VolumeChanged; ChromecastService.ChromeCastClient.MediaStatusChanged += ChromeCastClient_MediaStatusChanged; ChromecastService.ChromeCastClient.ConnectedChanged += ChromeCastClient_Connected; var chromecast = new Chromecast { DeviceUri = new Uri("http://192.168.178.158:8009"), FriendlyName = "Google Home" }; ChromecastService.ConnectToChromecast(chromecast); }
protected override async void OnCreate(Bundle bundle) { base.OnCreate(bundle); ChromecastService.ChromeCastClient.ConnectedChanged += ChromeCastClient_ConnectedChanged; ChromecastService.ChromeCastClient.ApplicationStarted += ChromeCastClient_ApplicationStarted; var devices = await ChromecastService.StartLocatingDevices(); ChromecastService.ConnectToChromecast(devices.First()); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.MyButton); button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); }; }