using System; using System.Collections.Generic; using System.Text; using Shared; namespace HDL_ON.UI.Music { [System.Serializable] public class A31MusicModel { public static List A31MusicModelList = new List { }; static readonly string a31MusiceModeListFilePath = "A31MusiceModeListFilePath"; static A31MusicModel() { Refresh(); //Type = DeviceType.A31MusicModel; } /// ///保存当前音乐列表 /// public static void Save() { 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(FileUtils.ReadFile(a31MusiceModeListFilePath)))) { A31MusicModelList = new List { }; //初始化房间列表 Save(); } else { A31MusicModelList = Newtonsoft.Json.JsonConvert.DeserializeObject>(System.Text.Encoding.UTF8.GetString(FileUtils.ReadFile(a31MusiceModeListFilePath))); } if (A31MusicModelList == null) { A31MusicModelList = new List { }; } A31MusicModelList.RemoveAll((obj) => obj == null); } /// /// 音乐播放器名称 /// public string Name; /// /// 上一次更新的时间 /// public DateTime LastDateTime; /// /// 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(); /// /// usb列表 /// public List USBList= new List(); /// /// Tidal喜爱列表 /// public List TidalLikelist = new List(); /// ///创建音乐文件列表 /// public List FileLists= 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 (); public static bool IsJson(string json) { try { if (null == Newtonsoft.Json.Linq.JObject.Parse(json)) { return false; } return true; } catch { return false; } } /// /// 调节音量 /// /// Volume. public void ControlVolume(int volume) { System.Threading.Tasks.Task.Run(() => { ProgressDateTime = DateTime.Now; try { if (ServerClientType == -1) { new System.Net.WebClient().DownloadData(new Uri("http://" + ServerIP + "/httpapi.asp?command=multiroom:SlaveVolume:" + IPAddress + ":" + volume)); } else if (ServerClientType == 1) { new System.Net.WebClient().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 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://" + IPAddress + ":" + Port + "/upnp/control/rendercontrol1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } } catch { } }); } } [System.Serializable] /// /// 自己创建的列表信息 /// public class FileListInfo { /// /// 列表名 /// 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; } }