Exemple #1
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);
        }
Exemple #2
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;
        }
Exemple #3
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);
        }
Exemple #4
0
        private async Task <TRANSPORTSTATE?> GetTransportInfo()
        {
            var command = AvCommands.ServiceActions.FirstOrDefault(c => c.Name == "GetTransportInfo");

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

            var service = GetAvTransportService();

            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);
        }
Exemple #5
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);
        }
Exemple #6
0
        public async Task <bool> SetNextAvTransport(string value, string header, string metaData)
        {
            var command = AvCommands.ServiceActions.FirstOrDefault(c => c.Name == "SetNextAVTransportURI");

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

            var dictionary = new Dictionary <string, string>
            {
                { "NextURI", value },
                { "NextURIMetaData", 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, value, dictionary), header)
                         .ConfigureAwait(false);

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

            return(true);
        }
Exemple #7
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);
        }