using Shared; using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Security.Cryptography; namespace Shared { [System.Serializable] public class A31MusicModel : MusicModel { public static List A31MusicModelList = new List { }; static readonly string a31MusiceModeListFilePath = "A31MusiceModeListFilePath"; static A31MusicModel () { Refresh (); } /// ///保存当前音乐列表 /// public static void Save () { IO.FileUtils.WriteFileByBytes (a31MusiceModeListFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (A31MusicModelList))); } public static void Refresh() { if (null == Newtonsoft.Json.JsonConvert.DeserializeObject> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (a31MusiceModeListFilePath)))) { A31MusicModelList = new List { }; //初始化房间列表 Save (); } else { A31MusicModelList = Newtonsoft.Json.JsonConvert.DeserializeObject> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (a31MusiceModeListFilePath))); } if (A31MusicModelList == null) { A31MusicModelList = new List { }; } A31MusicModelList.RemoveAll ((obj) => obj == null); } public A31MusicModel () { Type = DeviceType.A31MusicModel; } /// /// IP地址 /// public string IPAddress = "192.168.1.100"; /// /// 端口 /// public int Port = 49153; public bool IsEnd; public int A31DeviceType; //public string a31Source = "wifi"; //public string a31Source = string.Empty; public string UniqueDeviceName = string.Empty; /// /// 当前播放状态 /// public A31PlayStatus A31PlayStatus = new A31PlayStatus (); public MusicInfo CurrentMusic = new MusicInfo (); /// ///当前播放的列表信息 /// public List CurrentPlayMusicInfoList = new List (); /// /// 是否允许显示 /// public bool IsCanShow = true; /// /// 是否在线,如果在线就允许读取信息 /// public bool IsOnLine = true; /// /// 喜爱列表 /// public List LoveMusicInfoList = new List (); /// /// DLNA所有列表 /// public List dlnaMusicInfoLists = new List (); /// /// 电台所有列表 /// public List CnRadioInfoList = new List (); /// /// vTuner电台所有列表 /// public List vTunerList = new List (); /// /// 电台所有列表 /// public List CnLoveRadioInfoList = new List (); /// /// Pandora电台所有列表 /// public List PanRadioInfoList = new List (); /// /// Tidal喜爱列表 /// public List TidalLikelist = new List (); public List ListInfos = new List (); /// /// 当前的A31音乐播放器 /// public static A31MusicModel Current; /// /// -1表示从的0表示默认1表示主的 /// public int ServerClientType; /// /// 表示从的播放器IP /// public string ServerIP = string.Empty; public Slaves Slave = new Slaves (); public static DateTime ProgressDateTime = DateTime.Now; //static System.Threading.Tasks.Task task; //音量列表 //static List volumeCommandList = new List (); /// /// 调节音量 /// /// Volume. public void ControlVolume (int volume) { System.Threading.Tasks.Task.Run (() => { ProgressDateTime = DateTime.Now; try { if (ServerClientType == -1) { new Shared.Net.MyWebClient ().DownloadData (new Uri ("http://" + ServerIP + "/httpapi.asp?command=multiroom:SlaveVolume:" + IPAddress + ":" + volume)); } else if (ServerClientType == 1) { new Shared.Net.MyWebClient ().DownloadData (new Uri ("http://" + IPAddress + "/httpapi.asp?command=setPlayerCmd:slave_vol:" + volume)); } else { var sb = new StringBuilder (); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine ("0"); sb.AppendLine ("Master"); sb.AppendLine ("" + volume + ""); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); var webClient = new Shared.Net.MyWebClient (5000); 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://" + IPAddress + ":" + Port + "/upnp/control/rendercontrol1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ())); } } catch { } }); //lock (volumeCommandList) { // volumeCommandList.Add (volume); //} //if (task == null) { // task = System.Threading.Tasks.Task.Run (() => { // while (true) { // try { // System.Threading.Thread.Sleep (100); // int tempVolume = 0; // lock (volumeCommandList) { // if (0 == volumeCommandList.Count) { // continue; // } // tempVolume = volumeCommandList [volumeCommandList.Count - 1]; // volumeCommandList.Clear (); // } // ProgressDateTime = DateTime.Now; // if (ServerClientType == -1) { // new Shared.Net.MyWebClient ().DownloadData (new Uri ("http://" + ServerIP + "/httpapi.asp?command=multiroom:SlaveVolume:" + IPAddress + ":" + tempVolume)); // } else { // var sb = new StringBuilder (); // sb.AppendLine (""); // sb.AppendLine (""); // sb.AppendLine (""); // sb.AppendLine ("0"); // sb.AppendLine ("Master"); // sb.AppendLine ("" + tempVolume + ""); // sb.AppendLine (""); // sb.AppendLine (""); // sb.AppendLine (""); // var webClient = new Shared.Net.MyWebClient (5000); // 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://" + IPAddress + ":" + Port + "/upnp/control/rendercontrol1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ())); // } // } catch { } // } // }); //} } /// /// 播放 /// /// Play public void Play () { System.Threading.Tasks.Task.Run (() => { StringBuilder sb = new StringBuilder (); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine ("0"); sb.AppendLine ("1"); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (3000); webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Play\""); webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ())); } catch { } }); } public static bool IsJson (string json) { try { if (null == Newtonsoft.Json.Linq.JObject.Parse (json)) { return false; } return true; } catch { return false; } } /// /// 暂停 /// /// Pause public void Pause () { System.Threading.Tasks.Task.Run (() => { StringBuilder sb = new StringBuilder (); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine ("0"); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (3000); webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Pause\""); webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ())); } catch { } }); } /// /// 下一曲 /// /// Pause public void Next () { System.Threading.Tasks.Task.Run (() => { StringBuilder sb = new StringBuilder (); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine ("0"); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (5000); webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Next\""); webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ())); } catch { } }); } /// /// 上一曲 /// /// Pause public void Previous () { System.Threading.Tasks.Task.Run (() => { StringBuilder sb = new StringBuilder (); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (" "); sb.AppendLine ("0"); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (5000); webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Previous\""); webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ())); } catch { } }); } /// /// 快进 /// /// Seek public void Seek (string seekvolume) { System.Threading.Tasks.Task.Run (() => { StringBuilder sb = new StringBuilder (); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (" "); sb.AppendLine ("0"); sb.AppendLine ("REL_TIME"); sb.AppendLine ("" + seekvolume + ""); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (5000); webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Seek\""); webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ())); } catch { } }); } } [System.Serializable] /// /// 自己创建的列表信息 /// public class ListInfo { /// /// 列表名 /// public string ListName = string.Empty; /// /// 列表歌曲信息 /// public List MusicInfoList = new List (); } [System.Serializable] public class TidalMusicInfo : MusicInfo { public MusicInfo MusicInfo; public bool playurl = true; } [System.Serializable] public class Slaves { /// /// 从播放器值为0 /// public string slaves = "0"; public List slave_list = new List (); } [System.Serializable] public class Slave { public string name = string.Empty; public string mask = string.Empty; public string volume = string.Empty; public string mute = string.Empty; public string channel = string.Empty; public string ip = string.Empty; public string version = string.Empty; public string uuid = string.Empty; } }