Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Created June 9, 2020 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfversluis/698e810b3f7e982ed8d002bbfaa2c922 to your computer and use it in GitHub Desktop.
Save jfversluis/698e810b3f7e982ed8d002bbfaa2c922 to your computer and use it in GitHub Desktop.
public partial class MainPage : ContentPage
{
public string CastUrl { get; set; } = "https://icecast-qmusicnl-cdp.triple-it.nl/Qmusic_nl_live_32.aac";
public ObservableCollection<IReceiver> CastDevices { get; set; }
public IReceiver SelectedCastDevice { get; set; }
public Command StartCastCommand { get; set; }
public MainPage()
{
InitializeComponent();
Init();
StartCastCommand = new Command(StartCasting);
}
async void StartCasting()
{
var sender = new Sender();
// Connect to the Chromecast
await sender.ConnectAsync(SelectedCastDevice);
// Launch the default media receiver application
var mediaChannel = sender.GetChannel<IMediaChannel>();
await sender.LaunchAsync(mediaChannel);
// Load and play
var mediaStatus = await mediaChannel.LoadAsync(
new MediaInformation() { ContentId = CastUrl });
}
async Task Init()
{
// Use the DeviceLocator to find all Chromecasts on our network
var receivers = await new DeviceLocator().FindReceiversAsync();
CastDevices = new ObservableCollection<IReceiver>();
foreach (var r in receivers)
CastDevices.Add(r);
BindingContext = this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment