using System; using System.Collections.Generic; using Shared; using HDL_ON.Entity; namespace HDL_ON.UI.Music { [System.Serializable] public class A31MusicModel : Function { public static List A31MusicModelList = new List { }; static readonly string a31MusiceModeListFilePath = "A31MusiceModeListFilePath"; static A31MusicModel() { Refresh(); } static List updataMusicStatesListThread = new List(); /// /// 读取音乐状态 /// public static void ReadMusicStates() { RemoveListThread(); if (GetCollection) { for (int i = 0; i < A31MusicModelList.Count; i++) { var a31player = A31MusicModelList[i]; var musicThread = new System.Threading.Thread(() => { while (true) { System.Threading.Thread.Sleep(1000); if (!a31player.IsOnLine) { continue; } SendMethod.ReadStatus(a31player); } }) { IsBackground = true, Name = "A31" }; musicThread.Start(); updataMusicStatesListThread.Add(musicThread); } } } /// /// 移除之前的线程 /// public static void RemoveListThread() { for (int i = 0; i < updataMusicStatesListThread.Count;) { try { var thread = updataMusicStatesListThread[i]; if (thread.IsAlive) { thread.Abort(); } updataMusicStatesListThread.Remove(thread); } catch (Exception e) { MainPage.Log("clearA31Threads error : " + e.Message); } finally { MainPage.Log("clearA31Threads over"); } } } /// /// 音乐列表里是否有音乐被收藏过 /// static bool GetCollection { get { for (int i = 0; i < A31MusicModelList.Count; i++) { if (A31MusicModelList[i].collect) { return true; //查询是否有音乐被收藏过 } } return false; } } /// ///保存当前音乐列表 /// public static void Save() { Common.FileUtlis.Files.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(Common.FileUtlis.Files.ReadFile(a31MusiceModeListFilePath)))) { A31MusicModelList = new List { }; //初始化房间列表 Save(); } else { A31MusicModelList = Newtonsoft.Json.JsonConvert.DeserializeObject>(System.Text.Encoding.UTF8.GetString(Common.FileUtlis.Files.ReadFile(a31MusiceModeListFilePath))); } if (A31MusicModelList == null) { A31MusicModelList = new List { }; } A31MusicModelList.RemoveAll((obj) => obj == null); } /// /// 音乐播放器名称 /// public string Name = string.Empty; /// /// 上一次更新的时间 /// 记录数据反馈的时间(因为有时间网络差数据不回复,导致刷新当前播放音乐时间不正确) /// ((当前时间)DateTime.Now - (记录时间)LastDateTimeLastDateTime).TotalSeconds=误差时间(秒) /// public DateTime LastDateTime; /// /// IP地址 /// public string IPAddress = "192.168.1.100"; /// /// 端口 /// public int Port = 49153; /// /// 是否是播放器列表最后一个(true) /// public bool IsEnd = false; public int A31DeviceType; //public string a31Source = "wifi"; //public string a31Source = string.Empty; /// /// 音乐播放器ID /// 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 LoveRadioInfoList = 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; public int _ServerClientType; /// /// -1表示从的0表示默认1表示主的 /// public int ServerClientType { get { return _ServerClientType; } set { _ServerClientType = value; if(value == 0) { name = Name; } } } /// /// 记录主播放器IP /// public string MainPlayIP = string.Empty; public string _MainPlayName = string.Empty; /// /// 记录主播放器名称 /// public string MainPlayName { get { return _MainPlayName; } set { _MainPlayName = value; if(ServerClientType == 1) { name = value; } } } /// /// 记录主播放器是否被收藏(秀桡定义的) /// public bool MainPlayCollection = false; public Slaves Slave = new Slaves(); /// /// 记录时间 /// public static DateTime ProgressDateTime = DateTime.Now; public static bool IsJson(string json) { try { if (null == Newtonsoft.Json.Linq.JObject.Parse(json)) { return false; } return true; } catch { return false; } } /// /// 自定义日志输出 /// public static void LogMusic(string str) { var time = DateTime.Now; Console.WriteLine(time + str); } } [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; } }