Ejemplo n.º 1
0
        /// <summary>
        /// Starts
        /// </summary>
        public void Start()
        {
            _logger.LogInformation("UPNP manager is started");

            var mediaServersDiscovery = new MediaServersDiscovery(_loggerFactory, new[] { _localIp });

            mediaServersDiscovery.DevicesActivity.Where(e => e.Activity == DeviceActivity.Available).Subscribe(e =>
            {
                _logger.LogInformation($"Media Server found: {e.Device}");

                this._mediaServers.TryAdd(e.Device.UDN, e.Device);
            });

            mediaServersDiscovery.DevicesActivity.Where(e => e.Activity == DeviceActivity.Gone).Subscribe(e =>
            {
                _logger.LogInformation($"Media Server gone: {e.Device}");
                this._mediaServers.TryRemove(e.Device.UDN, out var gone);
            });


            var mediaRenderersDiscovery = new MediaRenderersDiscovery(_loggerFactory, new[] { _localIp });

            mediaRenderersDiscovery.DevicesActivity.Where(e => e.Activity == DeviceActivity.Available).Subscribe(e =>
            {
                _logger.LogInformation($"Renderer Server found: {e.Device}");
                this._rendererServers.TryAdd(e.Device.UDN, e.Device);
            });

            mediaRenderersDiscovery.DevicesActivity.Where(e => e.Activity == DeviceActivity.Gone).Subscribe(e =>
            {
                _logger.LogInformation($"Renderer Server gone: {e.Device}");
                this._rendererServers.TryRemove(e.Device.UDN, out var gone);
            });
        }
Ejemplo n.º 2
0
        public static void Test2(ILoggerFactory loggerFactory)
        {
            //var client = new HttpUClient();
            //client.OnResponse += Client_OnResponse;
            //client.BroadcastDisvoeryRequst();
            //var rendererDiscovery = new AVRendererDiscovery((new AVRendererDiscovery.DiscoveryHandler(RendererAddedSink)));

            //_containerDiscovery = ContainerDiscovery.GetInstance();

            //_containerDiscovery.AllRoots.OnContainerChanged += new CpRootContainer.Delegate_OnContainerChanged(ContainerChangedSink);


            var devicesDiscovery = new CommonUPnPDevicesDiscovery(loggerFactory);


            // Receiving notifications about new devices added to a network
            devicesDiscovery.DevicesActivity.Where(e => e.Activity == DeviceActivity.Available).Subscribe(e =>
            {
                Console.WriteLine("{0} found", e.Device.FriendlyName);
            });

            // Receiving notifications about devices left the network
            devicesDiscovery.DevicesActivity.Where(e => e.Activity == DeviceActivity.Gone).Subscribe(e =>
            {
                Console.WriteLine("{0} gone", e.Device.FriendlyName);
            });

            //  Receiving notifications about new devices of specific type added to the network
            var newMediaServers = from activityInfo in devicesDiscovery.DevicesActivity
                                  where activityInfo.Activity == DeviceActivity.Available && activityInfo.Device.DeviceType == "urn:schemas-upnp-org:device:MediaServer"
                                  select activityInfo.Device;

            newMediaServers.Subscribe(s =>
            {
                Console.WriteLine("{0} found", s.FriendlyName);
            });


            var mediaServersDiscovery   = new MediaServersDiscovery(loggerFactory);
            var mediaRenderersDiscovery = new MediaRenderersDiscovery(loggerFactory);

            // Enumerating currently available servers
            foreach (var server in mediaServersDiscovery.DiscoveredDevices)
            {
                Console.WriteLine("Server found: {0}", server.FriendlyName);
            }

            // Receiving notifications about new media servers added to a network
            mediaServersDiscovery.DevicesActivity.Where(e => e.Activity == DeviceActivity.Available).Subscribe(async e =>
            {
                Console.WriteLine("Server found: {0}", e.Device.FriendlyName);

                if (e.Device.FriendlyName == "raspberrypi: minidlna")
                {
                    //var rootObjects = await e.Device.BrowseAsync();
                    //var rootContainers = rootObjects.OfType<MediaContainer>();
                    //var rootMediaItems = rootObjects.OfType<MediaItem>();

                    //// Requesting media objects from child container
                    //var containerToBrowse = rootContainers.First(x=>x.Title=="Video");
                    //var childContainerObjects = await e.Device.BrowseAsync(containerToBrowse);

                    // var videos = await e.Device.SearchAsync<VideoItem>();

                    _mini = e.Device;
                }
            });

            // Receiving notifications about media renderers left the network
            mediaRenderersDiscovery.DevicesActivity.Where(e => e.Activity == DeviceActivity.Available).Subscribe(e =>
            {
                Console.WriteLine("Renderer found: {0}", e.Device.FriendlyName);
                if (e.Device.FriendlyName == "yangchao (CD-PC029 : Windows Media Player)")
                {
                    _renderer = e.Device;
                }
            });
        }