| | |
| | | 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(); |
| | |
| | | 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"); |
| | | |
| | |
| | | /// <summary> |
| | | /// 播放 |
| | | /// </summary> |
| | | public static void Play() |
| | | public static void Play(A31MusicModel a31player) |
| | | { |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | |
| | | 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> |
| | | public static void Pause() |
| | | public static void Pause(A31MusicModel a31player) |
| | | { |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | |
| | | 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> |
| | | public static void Next() |
| | | public static void Next(A31MusicModel a31player) |
| | | { |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | |
| | | 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> |
| | | public static void Previous() |
| | | public static void Previous(A31MusicModel a31player) |
| | | { |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | |
| | | 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> |
| | | public static void Seek(string seekvolume) |
| | | public static void Seek(string seekvolume, A31MusicModel a31player) |
| | | { |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | |
| | | 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; |
| | |
| | | /// <summary> |
| | | ///请求USB列表命令 |
| | | /// </summary> |
| | | public static string GetUSBPlayList() |
| | | public static string GetUSBPlayList(A31MusicModel a31player) |
| | | { |
| | | |
| | | StringBuilder getPlayList = new StringBuilder(); |
| | |
| | | |
| | | 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 { } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 读取电台组列表 |
| | | /// </summary> |
| | | /// <returns>读取到的电台组列表信息,读取不到反馈为null</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\"?>"); |
| | |
| | | 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 { } |
| | |
| | | /// </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\"?>"); |
| | |
| | | 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 { } |
| | |
| | | |
| | | return check_sum; |
| | | } |
| | | public class A31QQSong |
| | | public class A31QQSong |
| | | { |
| | | public string title = string.Empty; |
| | | public string album = string.Empty; |