From 7167334c0e89dd84827d59e726123d14776e3a09 Mon Sep 17 00:00:00 2001 From: 陈嘉乐 <cjl@hdlchina.com.cn> Date: 星期二, 16 六月 2020 11:14:13 +0800 Subject: [PATCH] 2020-06-16-1 --- HDL_ON/UI/Music/SendMethod.cs | 126 ++++++++++++++++++++++++++++++++---------- 1 files changed, 96 insertions(+), 30 deletions(-) diff --git a/HDL_ON/UI/Music/SendMethod.cs b/HDL_ON/UI/Music/SendMethod.cs index 7f04067..60ec371 100644 --- a/HDL_ON/UI/Music/SendMethod.cs +++ b/HDL_ON/UI/Music/SendMethod.cs @@ -153,22 +153,17 @@ try { - if (a31MusicModel.ServerClientType == -1) + if (a31MusicModel.ServerClientType == 1) { - var result = OpenWeb("http://" + a31MusicModel.ServerIP + "/httpapi.asp?command=multiroom:getSlaveList"); - if (result != null) + var result = OpenWeb("http://" + a31MusicModel.IPAddress + "/httpapi.asp?command=multiroom:getSlaveList"); + if (result != null && result != "Failed") { var slaves = Newtonsoft.Json.JsonConvert.DeserializeObject<Slaves>(result); - if (slaves != null && slaves.slave_list != null) + if (slaves != null && slaves.slave_list != null && slaves.slave_list.Count != 0) { - var slave = slaves.slave_list.Find((obj) => obj.uuid.Replace("uuid:", "") == a31MusicModel.UniqueDeviceName); - if (slave != null) - { - a31MusicModel.A31PlayStatus.vol = slave.volume; - } + a31MusicModel.Slave = slaves; } } - return; } WebClient webClient = new WebClient(); @@ -176,7 +171,7 @@ webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); var recevieBytes = webClient.UploadData(new Uri("http://" + a31MusicModel.IPAddress + ":" + a31MusicModel.Port + "/upnp/control/rendertransport1"), "POST", System.Text.Encoding.UTF8.GetBytes("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:GetInfoEx xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:GetInfoEx></s:Body></s:Envelope>")); - a31MusicModel.LastDateTime = DateTime.Now; + a31MusicModel.LastDateTime = DateTime.Now;//璁板綍鏁版嵁鍙嶉鐨勬椂闂�(鍥犱负鏈夋椂闂寸綉缁滃樊鏁版嵁涓嶅洖澶嶏紝瀵艰嚧褰撳墠鎾斁闊充箰鏃堕棿鏄剧ず涓嶆纭�) var se = System.Security.SecurityElement.FromString(System.Text.Encoding.UTF8.GetString(recevieBytes)).SearchForChildByTag("s:Body").SearchForChildByTag("u:GetInfoExResponse"); @@ -315,7 +310,7 @@ /// <summary> /// 鎾斁 /// </summary> - public static void Play() + public static void Play(A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { @@ -334,7 +329,7 @@ webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { - webClient.UploadData(new Uri("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); + webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } catch { } }); @@ -342,7 +337,7 @@ /// <summary> /// 鏆傚仠 /// </summary> - public static void Pause() + public static void Pause(A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { @@ -360,7 +355,7 @@ webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { - webClient.UploadData(new Uri("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); + webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } catch { } }); @@ -369,7 +364,7 @@ /// <summary> /// 涓嬩竴鏇� /// </summary> - public static void Next() + public static void Next(A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { @@ -387,7 +382,7 @@ webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { - webClient.UploadData(new Uri("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); + webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } catch { } }); @@ -396,7 +391,7 @@ /// <summary> /// 涓婁竴鏇� /// </summary> - public static void Previous() + public static void Previous(A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { @@ -414,7 +409,7 @@ webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { - webClient.UploadData(new Uri("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); + webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } catch { } }); @@ -423,7 +418,7 @@ /// <summary> /// 蹇繘 /// </summary> - public static void Seek(string seekvolume) + public static void Seek(string seekvolume, A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { @@ -443,20 +438,60 @@ webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { - webClient.UploadData(new Uri("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); + webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } catch { } }); } + /// <summary> + /// 璋冭妭闊抽噺 + /// </summary> + /// <param name="volume">Volume.</param> + public static void ControlVolume(int volume, A31MusicModel a31player) + { + System.Threading.Tasks.Task.Run(() => { + A31MusicModel.ProgressDateTime = DateTime.Now; + try + { + if (a31player.ServerClientType == -1) + { + new System.Net.WebClient().DownloadData(new Uri("http://" + a31player.MainPlayIP + "/httpapi.asp?command=multiroom:SlaveVolume:" + a31player.IPAddress + ":" + volume)); + } + else if (a31player.ServerClientType == 1) + { + new System.Net.WebClient().DownloadData(new Uri("http://" + a31player.IPAddress + "/httpapi.asp?command=setPlayerCmd:slave_vol:" + volume)); + } + else + { + var sb = new StringBuilder(); + sb.AppendLine("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"); + sb.AppendLine("<s:Body>"); + sb.AppendLine("<u:SetVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\">"); + sb.AppendLine("<InstanceID>0</InstanceID>"); + sb.AppendLine("<Channel>Master</Channel>"); + sb.AppendLine("<DesiredVolume>" + volume + "</DesiredVolume>"); + sb.AppendLine("</u:SetVolume>"); + sb.AppendLine("</s:Body>"); + sb.AppendLine("</s:Envelope>"); + var webClient = new System.Net.WebClient(); + webClient.Headers.Add("SOAPACTION", "\"urn:schemas-upnp-org:service:RenderingControl:1#SetVolume\""); + webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); + webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendercontrol1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); + } + } + catch { } + }); + + } /// <summary> /// 鑾峰彇USb鐨勫垪琛� /// </summary> - public static List<MusicInfo> GetUsbList() + public static List<MusicInfo> GetUsbList(A31MusicModel a31player) { var musicInfoList = new List<MusicInfo>(); musicInfoList.Clear(); - var usbString = GetUSBPlayList(); + var usbString = GetUSBPlayList(a31player); if (usbString == null) { return musicInfoList; @@ -489,7 +524,7 @@ /// <summary> ///璇锋眰USB鍒楄〃鍛戒护 /// </summary> - public static string GetUSBPlayList() + public static string GetUSBPlayList(A31MusicModel a31player) { StringBuilder getPlayList = new StringBuilder(); @@ -507,7 +542,7 @@ try { - byte[] recevieBytes = webClient.UploadData(new Uri("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(getPlayList.ToString())); + byte[] recevieBytes = webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(getPlayList.ToString())); return System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); } catch { } @@ -516,9 +551,40 @@ } /// <summary> + /// 璇诲彇鐢靛彴缁勫垪琛� + /// </summary> + /// <returns>璇诲彇鍒扮殑鐢靛彴缁勫垪琛ㄤ俊鎭紝璇诲彇涓嶅埌鍙嶉涓簄ull</returns> + public static string ReadRadioList(string url) + { + + WebClient webClient = new WebClient(); + webClient.Proxy = null; + webClient.Headers.Add("Content-type", "plain/text; charset=UTF-8"); + if (Language.CurrentLanguage == "Chinese") + { + webClient.Headers.Add("Accept-Language", "zh-cn"); + } + else + { + webClient.Headers.Add("Accept-Language", "en-us"); + } + try + { + byte[] recevieBytes = webClient.DownloadData(new Uri(url)); + return System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); + + } + catch (Exception e) + { + return null; + } + + } + + /// <summary> /// 鑾峰彇褰撳墠鎾斁鐨勫垪琛� /// </summary> - public static string GetCurrentPlayList() + public static string GetCurrentPlayList(A31MusicModel a31player) { System.Text.StringBuilder getPlayList = new System.Text.StringBuilder(); getPlayList.AppendLine("<?xml version=\"1.0\"encoding=\"utf-8\"?>"); @@ -535,7 +601,7 @@ webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { - byte[] recevieBytes = webClient.UploadData(new Uri("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(getPlayList.ToString())); + byte[] recevieBytes = webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(getPlayList.ToString())); return System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); } catch { } @@ -546,7 +612,7 @@ /// </summary> /// <param name="listName">鍒楄〃鍚嶇О</param> /// <param name="number">鎾斁绱㈠紩</param> - public static void ListMusicPlay(string listName, object number) + public static void ListMusicPlay(string listName, object number, A31MusicModel a31player) { System.Text.StringBuilder playstrings = new System.Text.StringBuilder(); playstrings.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>"); @@ -563,7 +629,7 @@ webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { - byte[] recevieBytes = webClient.UploadData(new Uri("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/PlayQueue1"), "POST", Encoding.UTF8.GetBytes(playstrings.ToString())); + byte[] recevieBytes = webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/PlayQueue1"), "POST", Encoding.UTF8.GetBytes(playstrings.ToString())); var s = System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); } catch { } @@ -632,7 +698,7 @@ return check_sum; } - public class A31QQSong + public class A31QQSong { public string title = string.Empty; public string album = string.Empty; -- Gitblit v1.8.0