Commit dce768ca authored by Martin Finkel's avatar Martin Finkel
Browse files

Fix chromecast sample and bump libvlc.ios version

parent 52de23ad
......@@ -154,7 +154,7 @@
<PackageReference Include="VideoLAN.LibVLC.iOS">
<PackageReference Include="Xamarin.Forms" Version="" />
using LibVLCSharp.Shared;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using static System.Diagnostics.Debug;
using Xamarin.Forms;
using System;
namespace Chromecast
......@@ -28,7 +31,7 @@ namespace Chromecast
// start chromecast discovery
// hold on a bit
// hold on a bit at first to give libvlc time to find the chromecast
await Task.Delay(5000);
// start casting if any renderer found
......@@ -42,24 +45,29 @@ namespace Chromecast
private void StartCasting()
// abort casting if no renderer items were found
if (!_rendererItems.Any()) return;
if (!_rendererItems.Any())
WriteLine("No renderer items found. Abort casting...");
// create new media
var media = new Media(_libVLC,
// create the mediaplayer from the media
_mediaPlayer = new MediaPlayer(media);
// create the mediaplayer
_mediaPlayer = new MediaPlayer(_libVLC);
// set the previously discovered renderer item (chromecast) on the mediaplayer
// if you set it to null, it will start to render normally (i.e. locally) again
// start the playback
private void DiscoverChromecasts()
void DiscoverChromecasts()
// load native libvlc libraries
......@@ -67,33 +75,36 @@ namespace Chromecast
// create core libvlc object
_libVLC = new LibVLC();
string rendererName;
// choose the correct service discovery protocol depending on the host platform
// Apple platforms use the Bonjour protocol
if (Device.RuntimePlatform == Device.iOS)
rendererName = _libVLC.RendererList.Select(renderer => renderer.Name).FirstOrDefault(name => name.Equals("Bonjour_renderer"));
else if (Device.RuntimePlatform == Device.Android)
rendererName = _libVLC.RendererList.Select(renderer => renderer.Name).FirstOrDefault(name => name.Equals("microdns_renderer"));
else throw new PlatformNotSupportedException("Only Android and iOS are currently supported in this sample");
// create a renderer discoverer
_rendererDiscoverer = new RendererDiscoverer(_libVLC, _libVLC.RendererList[0].Name);
_rendererDiscoverer = new RendererDiscoverer(_libVLC, rendererName);
// register callback when a new renderer is found
_rendererDiscoverer.ItemAdded += RendererDiscoverer_ItemAdded;
// start discovery on the local network
private void _libVLC_Log(object sender, LogEventArgs e)
var r = _rendererDiscoverer.Start();
/// <summary>
/// Raised when a renderer has been discovered or has been removed
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RendererDiscoverer_ItemAdded(object sender, RendererDiscovererItemAddedEventArgs e)
void RendererDiscoverer_ItemAdded(object sender, RendererDiscovererItemAddedEventArgs e)
Debug.WriteLine($"New item discovered: {e.RendererItem.Name} of type {e.RendererItem.Type}");
WriteLine($"New item discovered: {e.RendererItem.Name} of type {e.RendererItem.Type}");
if (e.RendererItem.CanRenderVideo)
Debug.WriteLine("Can render video");
WriteLine("Can render video");
if (e.RendererItem.CanRenderAudio)
Debug.WriteLine("Can render audio");
WriteLine("Can render audio");
// add newly found renderer item to local collection
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment