JLChen
2021-08-21 097511a2a666f1206fd78fdef0e213e09b5f46df
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
using System;
using System.Collections.Generic;
using Shared;
using Shared.IO;
using System.Net;
using HDL_ON.Entity;
 
namespace HDL_ON.UI.Music
{
    public class MusicMain : FrameLayout
    {
 
        /// <summary>
        /// MusicMain对象构造函数
        /// </summary>
        public MusicMain()
        {
            Tag = "MusicMain";
            //进来音乐列表界面先移除之前线程;
            A31MusicModel.RemoveListThread();
        }
        /// <summary>
        /// 重写RemoveFromParent方法
        /// </summary>
        public override void RemoveFromParent()
        {
            base.RemoveFromParent();
            clearA31Threads();
            A31MusicModel.ReadMusicStates();//进来没有音乐被收藏过,退出有音乐被收藏过
        }
        /// <summary>
        /// 创建线程列表
        /// </summary>
        static List<System.Threading.Thread> threadLists = new List<System.Threading.Thread>();
        /// <summary>
        /// 移除线程
        /// </summary>
        static void clearA31Threads()
        {
            var threads = threadLists.FindAll((obj) => { return obj.Name == "A31"; });
            foreach (var thread in threads)
            {
                try
                {
                    threadLists.Remove(thread);
                    if (thread.IsAlive)
                    {
                        ///强制线程抛异常
                        thread.Abort();
                    }
                }
                catch (Exception e)
                {
                    MainPage.Log("clearA31Threads error : " + e.Message);
                }
            }
        }
        /// <summary>
        ///  显示加载界面
        /// </summary>
        public static Loading loading = new Loading();
        /// <summary>
        /// 定义全局对象
        /// </summary>
        VerticalRefreshLayout verticalRefresh;
        /// <summary>
        /// 为了音乐刷新状态定义全局对象
        /// </summary>
        MusicView musicView = new MusicView();
        public void Show()
        {
            #region 界面布局
            this.BackgroundColor = MusicColor.ViewColor;
            var topView = new TopView();
            this.AddChidren(topView.TopFLayoutView());
            topView.topNameBtn.TextID = StringId.a31Music;
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
 
            verticalRefresh = new VerticalRefreshLayout
            {
                Y = topView.fLayout.Bottom,
                Height = Application.GetRealHeight(H_W.H - H_W.T_Height),
            };
            this.AddChidren(verticalRefresh);
            #endregion
 
            verticalRefresh.BeginHeaderRefreshingAction += () =>
            {
                SeachMusic();
            };
            this.AddChidren(loading);
            SeachMusic();
 
        }
        /// <summary>
        /// 刷新播放器列表
        /// </summary>
        void SeachMusic()
        {
            Application.RunOnMainThread(() =>
            {
                verticalRefresh.RemoveAll();
                for (int i = 0; i < SendMethod.sendMethod.GetMusicList.Count; i++)
                {
                    var playerFunction = SendMethod.sendMethod.GetMusicList[i]; 
                    if (!playerFunction.online)
                    {
                        //过滤掉不在线的音乐播放器
                        continue;
                    }
                    MusicListView(playerFunction);
                }
 
            });
 
        }
        /// <summary>
        /// 显示音乐列表的方法
        /// </summary>
        void MusicListView(Function player) 
        {
            musicView.View(verticalRefresh);
            musicView.singerBtn.Text = player.GetAttrState("song_name");
            musicView.songNameBtn.Text = player.GetAttrState("song_name");
            musicView.musicNameBtn.Text = player.name;
            //if (player.IsEnd)
            //{
            //    musicView.muiscFl.Height = Application.GetRealHeight(12 + 139 + 12);
            //}
 
            musicView.collectIconBtn.MouseUpEventHandler += (sender, e) =>
            {
                musicView.collectIconBtn.IsSelected = !musicView.collectIconBtn.IsSelected;
                if (musicView.collectIconBtn.IsSelected)
                {
                    player.collect = true;
                }
                else
                {
                    player.collect = false;
                }
            };
 
            EventHandler<MouseEventArgs> clickMergence = (sender, e) =>
            {
                //if (player.ServerClientType == 0)
                //{
                //    new View.DialogView { }.PlayMergence(player);
                //}
                //else if (player.ServerClientType == 1)
                //{
                //    new View.DialogView { }.DetachPlayMergence(player);
                //}
            };
            musicView.mergeBjBtn.MouseUpEventHandler += clickMergence;
            musicView.mergeBtn.MouseUpEventHandler += clickMergence;
            musicView.mergeIconBtn.MouseUpEventHandler += clickMergence;
 
            EventHandler<MouseEventArgs> clickPlayView = (sender, e) =>
            {
                var a31PlayMusicPage = new A31PlayMusicPage();
                MainPage.BasePageView.AddChidren(a31PlayMusicPage);
                a31PlayMusicPage.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            musicView.musicIfonFl.MouseUpEventHandler += clickPlayView;
            musicView.clickBtn.MouseUpEventHandler += clickPlayView;//
            musicView.singerBtn.MouseUpEventHandler += clickPlayView;
            musicView.songNameBtn.MouseUpEventHandler += clickPlayView;//
            musicView.musicNameBtn.MouseUpEventHandler += clickPlayView;
            musicView.regionBtn.MouseUpEventHandler += clickPlayView;//
 
            ///上一曲点击事件
            musicView.prevBtn.MouseDownEventHandler += (sender, e) =>
            {
                musicView.prevBtn.IsSelected = true;
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("song_step", "up");
                SendMethod.sendMethod.SendControlCommand(player, dic);
            };
            musicView.prevBtn.MouseUpEventHandler += (sender, e) =>
            {
                musicView.prevBtn.IsSelected = false;
            };
            ///暂停/播放点击事件
            musicView.playBtn.MouseDownEventHandler += (sender, e) =>
            {
                string status = "off";
                if (musicView.playBtn.IsSelected)
                {
                    musicView.playBtn.IsSelected = false;
                    status = "off";
                }
                else
                {
                    musicView.playBtn.IsSelected = true;
                    status = "on";
                }
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("on_off", status);
                SendMethod.sendMethod.SendControlCommand(player, dic);
            };
            ///下一曲点击事件
            musicView.nextBtn.MouseDownEventHandler += (sender, e) =>
            {
                musicView.nextBtn.IsSelected = true;
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("song_step", "down");
                SendMethod.sendMethod.SendControlCommand(player, dic);
            };
            musicView.nextBtn.MouseUpEventHandler += (sender, e) =>
            {
                musicView.nextBtn.IsSelected = false;
            };
 
            var musicThread = new System.Threading.Thread(() =>
            {
                while (true)
                {
                    System.Threading.Thread.Sleep(1000);
                    if (!player.online)
                    {
                        continue;
                    }
                    //SendMethod.ReadStatus(player);
                     SendMethod.sendMethod.RefreshDeviceStatus(player,new List<string> { player.deviceId });
                 
                    Application.RunOnMainThread(() =>
                    {
                        //musicView.singerBtn.Text = player.A31PlayStatus.Artist;
                        //musicView.songNameBtn.Text = player.A31PlayStatus.Title;
                        //musicView.musicNameBtn.Text = new View.DialogView { }.NamePlayer(player);
                        //if (player.A31PlayStatus.status == "play")
                        //{
                        //    musicView.playBtn.IsSelected = true;
                        //}
                        //else
                        //{
                        //    musicView.playBtn.IsSelected = false;
                        //}
                        //musicView.regionBtn.Text = player.GetRoomListName();
                        //if (player.ServerClientType == 1)
                        //{
                        //    if (player.MainPlayCollection)
                        //    {
                        //        musicView.collectIconBtn.IsSelected = true;
                        //    }
                        //    else
                        //    {
                        //        musicView.collectIconBtn.IsSelected = false;
                        //    }
                        //}
                        //else
                        //{
                        //    if (player.collect)
                        //    {
                        //        musicView.collectIconBtn.IsSelected = true;
                        //    }
                        //    else
                        //    {
                        //        musicView.collectIconBtn.IsSelected = false;
                        //    }
                        //}
                    });
                }
            })
            { IsBackground = true, Name = "A31" };
            musicThread.Start();
            threadLists.Add(musicThread);
        }
 
        /// <summary>
        ///指定刷新界面
        /// </summary>
        /// <param name="strView">判断字符</param>
        public void RefreshView(string strView)
        {
            Application.RunOnMainThread(() =>
            {
                try
                {
                  
                    for (int i = MainPage.BasePageView.ChildrenCount - 1; 0 <= i; i--)
                    {
                        var view = MainPage.BasePageView.GetChildren(i);
                        if (strView == view.Tag.ToString())
                        {
                            if (view.GetType() == typeof(MusicMain))
                            {
                                //musicView.singerBtn.Text = player.A31PlayStatus.Artist;
                                //musicView.songNameBtn.Text = player.A31PlayStatus.Title;
                                //musicView.musicNameBtn.Text = new View.DialogView { }.NamePlayer(player);
                                //if (player.A31PlayStatus.status == "play")
                                //{
                                //    musicView.playBtn.IsSelected = true;
                                //}
                                //else
                                //{
                                //    musicView.playBtn.IsSelected = false;
                                //}
                                //musicView.regionBtn.Text = player.GetRoomListName();
                                //if (player.ServerClientType == 1)
                                //{
                                //    if (player.MainPlayCollection)
                                //    {
                                //        musicView.collectIconBtn.IsSelected = true;
                                //    }
                                //    else
                                //    {
                                //        musicView.collectIconBtn.IsSelected = false;
                                //    }
                                //}
                                //else
                                //{
                                //    if (player.collect)
                                //    {
                                //        musicView.collectIconBtn.IsSelected = true;
                                //    }
                                //    else
                                //    {
                                //        musicView.collectIconBtn.IsSelected = false;
                                //    }
                                //}
                            }
                        }
 
                    }
                }
                catch { }
            });
        }
    }
 
}