Exemplo n.º 1
0
        public void DiscoverChromecasts()
        {
            var rendererDiscoverer = new RendererDiscoverer(_libVLC);

            rendererDiscoverer.ItemAdded += RendererDiscoverer_ItemAdded;
            rendererDiscoverer.Start();
        }
Exemplo n.º 2
0
        void DiscoverChromecasts()
        {
            // load native libvlc libraries
            Core.Initialize();

            // 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, rendererName);

            // register callback when a new renderer is found
            _rendererDiscoverer.ItemAdded += RendererDiscoverer_ItemAdded;

            // start discovery on the local network
            var r = _rendererDiscoverer.Start();
        }
Exemplo n.º 3
0
Arquivo: Program.cs Projeto: tdav/lvst
        private static async Task <bool> FindAndUseChromecast()
        {
            using var rendererDiscoverer  = new RendererDiscoverer(libVLC);
            rendererDiscoverer.ItemAdded += RendererDiscoverer_ItemAdded;
            if (rendererDiscoverer.Start())
            {
                WriteLine("LibVLCSharp -> Searching for chromecasts...");
                // give it some time...
                await Task.Delay(2000);
            }
            else
            {
                WriteLine("LibVLCSharp -> Failed starting the chromecast discovery");
            }

            rendererDiscoverer.ItemAdded -= RendererDiscoverer_ItemAdded;

            if (!renderers.Any())
            {
                WriteLine("LibVLCSharp -> No chromecast found... aborting.");
                return(false);
            }

            mediaPlayer.SetRenderer(renderers.First());
            return(true);
        }
Exemplo n.º 4
0
        static async Task Main(string[] args)
        {
            Core.Initialize();
            var rendererItems = new HashSet <RendererItem>();

            using var libvlc      = new LibVLC("--verbose=2");
            using var mediaPlayer = new MediaPlayer(libvlc);
            using var media       = new Media(libvlc, "screen://", FromType.FromLocation);
            var renderer   = libvlc.RendererList.FirstOrDefault();
            var discoverer = new RendererDiscoverer(libvlc, renderer.Name);

            discoverer.ItemAdded += (object sender, RendererDiscovererItemAddedEventArgs args) =>
            {
                rendererItems.Add(args.RendererItem);
            };
            discoverer.Start();


            media.AddOption(":screen-fps=24");
            media.AddOption(":sout=#transcode{vcodec=h264,vb=0,scale=0,acodec=mp4a,ab=128,channels=2,samplerate=44100}:standard{access=http,mux=ts,dst=localhost:8080}");
            media.AddOption(":sout-keep");


            await Task.Delay(TimeSpan.FromSeconds(5)); // wait for 5 seconds

            mediaPlayer.SetRenderer(rendererItems.First());

            mediaPlayer.Play(media);                     // start recording

            await Task.Delay(TimeSpan.FromMinutes(2.0)); // record for 2 minutes

            mediaPlayer.Stop();                          // stop recording and saves the file
        }
        public void DisposeRendererDiscoverer()
        {
            var rendererDiscoverer = new RendererDiscoverer(_libVLC, _libVLC.RendererList.LastOrDefault().Name);

            rendererDiscoverer.Start();
            rendererDiscoverer.Dispose();
            Assert.AreEqual(IntPtr.Zero, rendererDiscoverer.NativeReference);
        }
Exemplo n.º 6
0
        public void DisposeRendererDiscoverer()
        {
            var rendererDiscoverer = new RendererDiscoverer(new LibVLC());

            rendererDiscoverer.Start();
            rendererDiscoverer.Dispose();
            Assert.AreEqual(IntPtr.Zero, rendererDiscoverer.NativeReference);
        }
        /// <summary>
        /// Finds the Chromecast renderers.
        /// </summary>
        /// <param name="libVLC">The <see cref="LibVLC"/> instance.</param>
        /// <returns>An enumerable collection of <see cref="RendererItem"/> representing the Chromecast renderers.</returns>
        public static async Task <IEnumerable <RendererItem> > FindRenderersAsync(this LibVLC libVLC)
        {
            var renderers = new List <RendererItem>();

            using (var rendererDiscover = new RendererDiscoverer(libVLC,
                                                                 Device.RuntimePlatform == Device.iOS ? "Bonjour_renderer" : "microdns_renderer"))
            {
                rendererDiscover.ItemAdded += (sender, e) => renderers.Add(e.RendererItem);
                rendererDiscover.Start();
                await Task.Delay(3000);
            }
            return(renderers);
        }
Exemplo n.º 8
0
        public async Task DiscoverItems()
        {
            Core.Initialize();

            var libVLC = new LibVLC();

            var mp = new MediaPlayer(libVLC)
            {
                Media = new Media(libVLC, "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4",
                                  Media.FromType.FromLocation)
            };

            Assert.True(mp.Play());

            var rendererList = libVLC.RendererList;

            Assert.IsNotEmpty(rendererList);

            var rendererDiscoverer = new RendererDiscoverer(libVLC);
            var rendererItems      = new List <RendererItem>();
            var tcs = new TaskCompletionSource <bool>();

            rendererDiscoverer.ItemAdded += (sender, args) =>
            {
                WriteLine($"New item discovered: {args.RendererItem.Name} of type {args.RendererItem.Type}");
                if (args.RendererItem.CanRenderVideo)
                {
                    WriteLine("Can render video");
                }
                if (args.RendererItem.CanRenderAudio)
                {
                    WriteLine("Can render audio");
                }

                rendererItems.Add(args.RendererItem);

                tcs.SetResult(true);
            };


            Assert.True(rendererDiscoverer.Start());

            await tcs.Task;

            Assert.True(tcs.Task.Result);
            Assert.IsNotEmpty(rendererItems);
            Assert.True(mp.SetRenderer(rendererItems.First()));

            await Task.Delay(10000);
        }
Exemplo n.º 9
0
        bool DiscoverChromecasts()
        {
            // load native libvlc libraries
            Core.Initialize();

            // create core libvlc object
            _libVLC = new LibVLC();

            // create a renderer discoverer
            _rendererDiscoverer = new RendererDiscoverer(_libVLC);

            // register callback when a new renderer is found
            _rendererDiscoverer.ItemAdded += RendererDiscoverer_ItemAdded;

            // start discovery on the local network
            return(_rendererDiscoverer.Start());
        }
Exemplo n.º 10
0
        public RenderersViewModel(ILoggingService loggingService, IOnlineTelevizorConfiguration config, IDialogService dialogService)
            : base(loggingService, config, dialogService)
        {
            _loggingService = loggingService;
            _dialogService  = dialogService;
            Config          = config;

            // load native libvlc libraries
            Core.Initialize();

            // create core libvlc object
            _libVLC = new LibVLC();

            // create a renderer discoverer
            _rendererDiscoverer = new RendererDiscoverer(_libVLC);

            // register callback when a new renderer is found
            _rendererDiscoverer.ItemAdded += RendererDiscoverer_ItemAdded;

            // start discovery on the local network
            _rendererDiscoverer.Start();
        }