This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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