陈嘉乐
2020-07-30 d18004970b3040ea27beb567694b496a56bedd5b
HDL_ON/UI/UI2/FuntionControlView/Music/A31MusicModel.cs
@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.Entity;
using Shared;
using HDL_ON.Entity;
namespace HDL_ON.UI.Music
{
@@ -14,7 +14,77 @@
        static A31MusicModel()
        {
            Refresh();
            //Type = DeviceType.A31MusicModel;
        }
        static List<System.Threading.Thread> updataMusicStatesListThread = new List<System.Threading.Thread>();
        /// <summary>
        /// 读取音乐状态
        /// </summary>
        public static void ReadMusicStates()
        {
            var threads = updataMusicStatesListThread.FindAll((obj) => { return obj.Name == "A31"; });
            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");
                }
            }
            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;
                            }
                            //A31MusicModel.ReadMusicStates();
                            SendMethod.ReadStatus(a31player);
                        }
                    })
                    { IsBackground = true, Name = "A31" };
                    musicThread.Start();
                    updataMusicStatesListThread.Add(musicThread);
                }
            }
        }
        /// <summary>
        /// 音乐列表里是否有音乐被收藏过
        /// </summary>
         static bool GetCollection
        {
            get
            {
                for (int i = 0; i < A31MusicModelList.Count; i++)
                {
                    if (A31MusicModelList[i].collection)
                    {
                        return true; //查询是否有音乐被收藏过
                    }
                }
                return false;
            }
        }
        /// <summary>
        ///保存当前音乐列表
@@ -42,7 +112,6 @@
            }
            A31MusicModelList.RemoveAll((obj) => obj == null);
        }
        /// <summary>
        /// 音乐播放器名称
@@ -73,6 +142,9 @@
        //public string a31Source = "wifi";
        //public string a31Source = string.Empty;
        /// <summary>
        /// 音乐播放器ID
        /// </summary>
        public string UniqueDeviceName = string.Empty;
        /// <summary>
@@ -143,20 +215,53 @@
        /// </summary>
        public static A31MusicModel Current;
        public int _ServerClientType;
        /// <summary>
        /// -1表示从的0表示默认1表示主的
        /// </summary>
        public int ServerClientType;
        public int ServerClientType
        {
            get
            {
                return _ServerClientType;
            }
            set
            {
                _ServerClientType = value;
                if(value == 0)
                {
                    name = Name;
                }
            }
        }
        /// <summary>
        /// 记录主播放器IP
        /// </summary>
        public string MainPlayIP = string.Empty;
        public string _MainPlayName = string.Empty;
        /// <summary>
        /// 记录主播放器名称
        /// </summary>
        public string MainPlayName = string.Empty;
        public string MainPlayName
        {
            get
            {
                return _MainPlayName;
            }
            set
            {
                _MainPlayName = value;
                if(ServerClientType == 1)
                {
                    name = value;
                }
            }
        }
        /// <summary>
        /// 记录主播放器是否被收藏
        /// </summary>
        public bool MainPlayCollection = false;
        public Slaves Slave = new Slaves();
@@ -180,9 +285,6 @@
                return false;
            }
        }
        
    }
    [System.Serializable]
@@ -227,7 +329,4 @@
        public string version = string.Empty;
        public string uuid = string.Empty;
    }
}