コード例 #1
0
        public bool Command(string cmd, string parameter)
        {
            if (Globals.ClientSupportsRemoteControl == null)
            {
                _parent.Log("EMBY COMMAND: ClientSupportsRemote currently null rechecking...");
                Globals.ClientSupportsRemoteControl = _parent.GetPlaybackClientSupportsRemote();
                _parent.Log("EMBY COMMAND: ClientSupportsRemote now:" + Globals.ClientSupportsRemoteControl);
            }

            if (Globals.ClientSupportsRemoteControl == false)
            {
                _parent.Log("-----EMBY COMMAND:   Current Client DOES NOT SUPPORT REMOTE CONTROL -- No Command Sent");
                _parent.Log("-----EMBY COMMAND:  GLobals SupportsRemote " + Globals.ClientSupportsRemoteControl + "Global ClientID:" + Globals.SessionIDClient);
                return(false);
            }

            if (String.IsNullOrEmpty(Globals.SessionIDClient))
            {
                Globals.SessionIDClient = _parent.GetYatseInfoPlayingClient();
            }

            HttpWebRequest request;
            var            returnContent = false;
            var            authString    = _parent.GetAuthString();

            var uri = @"http://" + _parent.IP + ":" + _parent.Port + "/emby/Sessions/" + Globals.SessionIDClient + "/Playing/";

            if (!String.IsNullOrEmpty(cmd))
            {
                uri += cmd;
            }


            _parent.Log(" ---------EMBY PLAY COMMAND: TESTING URL:" + uri + ":::::");

            try
            {
                request = (HttpWebRequest)WebRequest.Create(new Uri(uri));
                request.Headers.Add("X-MediaBrowser-Token", Globals.EmbyAuthToken);
                request.Headers.Add("X-Emby-Authorization", authString);
                request.ContentType = "application/json";

                ASCIIEncoding encoder = new ASCIIEncoding();
                byte[]        data    = encoder.GetBytes("");


                request.ContentLength = data.Length;
                request.Expect        = "application/json";

                request.Method  = "POST";
                request.Timeout = 1000;
                _parent.Log("Emby COMMAND  : " + cmd);
                _parent.Trace(uri);


                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    using (var stream = response.GetResponseStream())
                    {
                        if (stream != null)
                        {
                            using (var reader = new StreamReader(stream, Encoding.UTF8))
                            {
                                var reqContent = reader.ReadToEnd();
                                _parent.Trace(reqContent);
                                returnContent = true;
                            }
                        }
                    }
                }
            }
            catch (WebException e)
            {
                _parent.Log("ERROR - EMBY  Command : " + cmd + " - " + e.Message);
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    // _parent.MpcLoaded = false;
                }
            }
            return(returnContent);
        }