Skip to content

Instantly share code, notes, and snippets.

@jfversluis
Created June 9, 2020 19:14
Embed
What would you like to do?
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