Exemplo n.º 1
0
        public async Task SetAvTransport(string url, string header, string metaData)
        {
            _logger.Debug("{0} - SetAvTransport Uri: {1} DlnaHeaders: {2}", Properties.Name, url, header);

            var command = AvCommands.ServiceActions.FirstOrDefault(c => c.Name == "SetAVTransportURI");

            if (command == null)
            {
                return;
            }

            var dictionary = new Dictionary <string, string>
            {
                { "CurrentURI", url },
                { "CurrentURIMetaData", CreateDidlMeta(metaData) }
            };

            var service = Properties.Services.FirstOrDefault(s => s.ServiceType == ServiceAvtransportType);

            if (service == null)
            {
                throw new InvalidOperationException("Unable to find service");
            }

            var post = AvCommands.BuildPost(command, service.ServiceType, url, dictionary);

            await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, post, header: header)
            .ConfigureAwait(false);

            await Task.Delay(50).ConfigureAwait(false);

            try
            {
                await SetPlay().ConfigureAwait(false);
            }
            catch
            {
                // Some devices will throw an error if you tell it to play when it's already playing
                // Others won't
            }

            RestartTimer();
        }
Exemplo n.º 2
0
        private async Task <TRANSPORTSTATE?> GetTransportInfo()
        {
            var command = AvCommands.ServiceActions.FirstOrDefault(c => c.Name == "GetTransportInfo");

            if (command == null)
            {
                return(null);
            }

            var service = Properties.Services.FirstOrDefault(s => s.ServiceType == ServiceAvtransportType);

            if (service == null)
            {
                return(null);
            }

            var result = await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType), false)
                         .ConfigureAwait(false);

            if (result == null || result.Document == null)
            {
                return(null);
            }

            var transportState =
                result.Document.Descendants(uPnpNamespaces.AvTransport + "GetTransportInfoResponse").Select(i => i.Element("CurrentTransportState")).FirstOrDefault(i => i != null);

            var transportStateValue = transportState == null ? null : transportState.Value;

            if (transportStateValue != null)
            {
                TRANSPORTSTATE state;

                if (Enum.TryParse(transportStateValue, true, out state))
                {
                    return(state);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        public async Task SetPause()
        {
            var command = AvCommands.ServiceActions.FirstOrDefault(c => c.Name == "Pause");

            if (command == null)
            {
                return;
            }

            var service = Properties.Services.First(s => s.ServiceType == ServiceAvtransportType);

            await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, 1))
            .ConfigureAwait(false);

            TransportState = TRANSPORTSTATE.PAUSED;
        }
Exemplo n.º 4
0
        public async Task SetPlay()
        {
            var command = AvCommands.ServiceActions.FirstOrDefault(c => c.Name == "Play");

            if (command == null)
            {
                return;
            }

            var service = Properties.Services.FirstOrDefault(s => s.ServiceType == ServiceAvtransportType);

            if (service == null)
            {
                throw new InvalidOperationException("Unable to find service");
            }

            await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, 1))
            .ConfigureAwait(false);
        }
Exemplo n.º 5
0
        public async Task Seek(TimeSpan value)
        {
            var command = AvCommands.ServiceActions.FirstOrDefault(c => c.Name == "Seek");

            if (command == null)
            {
                return;
            }

            var service = Properties.Services.FirstOrDefault(s => s.ServiceType == ServiceAvtransportType);

            if (service == null)
            {
                throw new InvalidOperationException("Unable to find service");
            }

            await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, String.Format("{0:hh}:{0:mm}:{0:ss}", value), "REL_TIME"))
            .ConfigureAwait(false);
        }
Exemplo n.º 6
0
        public async Task SetStop()
        {
            var command = AvCommands.ServiceActions.FirstOrDefault(c => c.Name == "Stop");

            if (command == null)
            {
                return;
            }

            var service = GetAvTransportService();

            await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, 1))
            .ConfigureAwait(false);
        }
Exemplo n.º 7
0
        public async Task SetNextAvTransport(string value, string header, string metaData)
        {
            var command = AvCommands.ServiceActions.FirstOrDefault(c => c.Name == "SetNextAVTransportURI");

            if (command == null)
            {
                return;
            }

            var dictionary = new Dictionary <string, string>
            {
                { "NextURI", value },
                { "NextURIMetaData", CreateDidlMeta(metaData) }
            };

            var service = Properties.Services.FirstOrDefault(s => s.ServiceType == ServiceAvtransportType);

            if (service == null)
            {
                throw new InvalidOperationException("Unable to find service");
            }

            await new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, value, dictionary), header)
            .ConfigureAwait(false);

            RestartTimer();
        }
Exemplo n.º 8
0
        public async Task <bool> SetAvTransport(string url, string header, string metaData)
        {
            StopTimer();

            TransportState = "STOPPED";
            CurrentId      = "0";

            await Task.Delay(50).ConfigureAwait(false);

            var command = AvCommands.ServiceActions.FirstOrDefault(c => c.Name == "SetAVTransportURI");

            if (command == null)
            {
                return(false);
            }

            var dictionary = new Dictionary <string, string>
            {
                { "CurrentURI", url },
                { "CurrentURIMetaData", CreateDidlMeta(metaData) }
            };

            var service = Properties.Services.FirstOrDefault(s => s.ServiceId == ServiceAvtransportId);

            if (service == null)
            {
                throw new InvalidOperationException("Unable to find service");
            }

            var result = await new SsdpHttpClient(_httpClient).SendCommandAsync(Properties.BaseUrl, service, command.Name, AvCommands.BuildPost(command, service.ServiceType, url, dictionary), header)
                         .ConfigureAwait(false);

            if (!IsPlaying)
            {
                await Task.Delay(50).ConfigureAwait(false);
                await SetPlay().ConfigureAwait(false);
            }

            _count = 5;
            RestartTimer();

            return(true);
        }