public static bool SetVolume(string ip, string psk, int volume)
        {
            try
            {
                BraviaParameter volumeParam = new BraviaParameter();
                volumeParam.Key       = "volume";
                volumeParam.IsLiteral = false;
                volumeParam.Value     = volume.ToString();

                BraviaParameter targetParam = new BraviaParameter();
                targetParam.Key       = "target";
                targetParam.IsLiteral = false;
                targetParam.Value     = "speaker";

                BraviaParameter uiParam = new BraviaParameter();
                uiParam.Key       = "ui";
                uiParam.IsLiteral = false;
                uiParam.Value     = "on";

                string method = "setAudioVolume";

                Send(ip, psk, "audio", method, "1.2", volumeParam, targetParam, uiParam);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public static ContentListInformation GetPlayContentsList(string ip, string psk)
        {
            BraviaParameter stdIxParam = new BraviaParameter();

            stdIxParam.IsLiteral = true;
            stdIxParam.Key       = "stdIx";
            stdIxParam.Value     = "0";

            BraviaParameter cntParam = new BraviaParameter();

            cntParam.IsLiteral = true;
            cntParam.Key       = "cnt";
            cntParam.Value     = "50";

            BraviaParameter uriParam = new BraviaParameter();

            uriParam.IsLiteral = false;
            uriParam.Key       = "uri";
            uriParam.Value     = "extInput:tv";

            string json     = GetJson("getContentList", "1.5", new BraviaParameter[] { stdIxParam, cntParam, uriParam });
            string dest     = $"http://{ip}/sony/avContent";
            string response = XmlHttpRequest(dest, psk, json);

            return(JsonConvert.DeserializeObject <ContentListInformation>(response));
        }
        public static bool SetPlayingContent(string ip, string psk, BraviaPlayContent playContent)
        {
            try
            {
                BraviaParameter parameter = new BraviaParameter();
                parameter.Key       = "uri";
                parameter.IsLiteral = false;
                parameter.Value     = BraviaMaps.GetEnumMap(playContent);
                string method = "setPlayContent";

                Send(ip, psk, "avContent", method, "1.0", parameter);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public static bool SetPowerStatus(string ip, string psk, BraviaPowerStatus powerStatus)
        {
            try
            {
                BraviaParameter parameter = new BraviaParameter();
                parameter.Key       = "status";
                parameter.IsLiteral = true;
                parameter.Value     = BraviaMaps.GetEnumMap(powerStatus);
                string method = "setPowerStatus";

                Send(ip, psk, "system", method, "1.0", parameter);

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        private static string GetStringFromParameters(BraviaParameter[] parameters)
        {
            if (parameters == null || !parameters.Any())
            {
                return("{}");
            }
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            for (int i = 0; i < parameters.Length; i++)
            {
                BraviaParameter param = parameters[i];
                sb.Append("\"");
                sb.Append(param.Key);
                sb.Append("\":");
                if (!param.IsLiteral)
                {
                    sb.Append("\"");
                }

                sb.Append(param.Value);

                if (!param.IsLiteral)
                {
                    sb.Append("\"");
                }

                if (i < parameters.Length - 1)
                {
                    sb.Append(",");
                }
            }

            sb.Append("}");

            return(sb.ToString());
        }