コード例 #1
0
ファイル: Device.cs プロジェクト: ploughpuff/jellyfin
        private async Task <TRANSPORTSTATE?> GetTransportInfo(TransportCommands avCommands, CancellationToken cancellationToken)
        {
            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);
        }
コード例 #2
0
ファイル: Device.cs プロジェクト: ploughpuff/jellyfin
        private Task SetPlay(TransportCommands avCommands, CancellationToken cancellationToken)
        {
            var command = avCommands.ServiceActions.FirstOrDefault(c => c.Name == "Play");

            if (command == null)
            {
                return(Task.CompletedTask);
            }

            var service = GetAvTransportService();

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

            return(new SsdpHttpClient(_httpClient, _config).SendCommandAsync(Properties.BaseUrl, service, command.Name, avCommands.BuildPost(command, service.ServiceType, 1)));
        }