黄学彪
2020-12-17 6c0c799c1f5da2d215ec8d9df9b92b3d1948dc14
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
using System;
using System.Collections.Generic;
using Shared;
using HDL_ON.UI.Music;
namespace HDL_ON.UI.UI2.FuntionControlView.Music
{
    public class UpdateThread
    {
        public UpdateThread()
        {
        }
        /// <summary>
        /// 定时更新当前播放音乐
        /// </summary>
        /// <param name="frame">当前界面</param>
        /// <param name="middViewLayout">每一条音乐的主控件</param>
        /// <param name="a31MusicModel">点前播放器</param>
        public static void updateThread(FrameLayout frame, VerticalRefreshLayout middViewLayout, A31MusicModel a31MusicModel)
        {
            System.Threading.Thread updateSelectedMusicThread = new System.Threading.Thread(() =>
            {
                while (frame.Parent != null)
                {
                    //A31MusicModel.LogMusic("已启动更新音乐列表某一条音乐状态的线程");
                    System.Threading.Thread.Sleep(1000);
                    Application.RunOnMainThread(() =>
                    {
                        try
                        {
                            for (int i = 0; i < middViewLayout.ChildrenCount; i++)
                            {
                                RowLayout view = (RowLayout)middViewLayout.GetChildren(i);
                                var volIconBtn = (Button)view.GetChildren(0);//直接FrameLayout父控件找到该控件Button
                                var songNameBtn = (Button)view.GetChildren(1);//直接FrameLayout父控件找到该控件Button
                                var artistNameBtn = (Button)view.GetChildren(2);//直接FrameLayout父控件找到该控件Button
                                if (a31MusicModel.A31PlayStatus.TrackURL == songNameBtn.Tag.ToString())
                                {
                                    volIconBtn.Visible = true;
                                    songNameBtn.TextColor = UI.Music.MusicColor.SelectedColor;
                                    songNameBtn.X = Application.GetRealWidth(48);
                                    artistNameBtn.X = songNameBtn.Right;
                                    artistNameBtn.TextColor = UI.Music.MusicColor.SelectedColor;
                                }
                                else
                                {
                                    volIconBtn.Visible = false;
                                    songNameBtn.TextColor = UI.Music.MusicColor.MusicTxet14Color;
                                    songNameBtn.X = Application.GetRealWidth(16);
                                    artistNameBtn.X = songNameBtn.Right;
                                    artistNameBtn.TextColor = UI.Music.MusicColor.MusicNoTxetColor;
                                }
 
 
                            }
                        }
                        catch { }
 
                    });
                }
            });
            updateSelectedMusicThread.Start();
        }
        /// <summary>
        /// 播放音乐
        /// </summary>
        /// <param name="middViewLayout">上下拉动父控件</param>
        /// <param name="musicSource">音乐源</param>
        /// <param name="listName">播放列表名</param>
        /// <param name="musicList">播放音乐列表</param>
        /// <param name="a31MusicModel">音乐播放器</param>
        public static void playMusuc(VerticalRefreshLayout middViewLayout, string musicSource, string listName,List<MusicInfo> musicList, A31MusicModel a31MusicModel, FrameLayout frame=null)
        {
            for (int i = 0; i < musicList.Count; i++)
            {
                var songs = musicList[i];
                if (songs == null)
                {
                    continue;
                }
                UI.Music.View.SongView songView = new UI.Music.View.SongView();
                songView.SongFrameLayout(middViewLayout, songs);
                switch (musicSource)
                {
                    case "本地音乐":
                        {
                            songs.URL = "http://" + new Shared.Net.NetWiFi().IpAddress + ":" + com.hdl.on.Server.Port + "/" + songs.ID;
                        }
                        break;
                    case "USB":
                        {
                            songView.clickBtn.Tag = i + 1;
                        }
                        break;
                    case "我的列表":
                        {
                            ///删除控件
                            var delBtn = new Button
                            {
                                BackgroundColor = MusicColor.MusicDelColor,
                                Text = Language.StringByID(StringId.delMusic),
                                TextColor = MusicColor.WhiteColor,
                                TextSize = TextSize.Text16,
                            };
                            songView.musicViewFl.AddRightView(delBtn);
                            delBtn.MouseUpEventHandler += (sender, e) =>
                            {
                                musicList.Remove(songs);
                                A31MusicModel.Save();
                                songView.musicViewFl.RemoveFromParent();
                            };
                        }
                        break;
                    case "播放列表":
                        {
                            songView.loveIcon.Visible = false;
                            songView.addIcon.Visible = false;
                            var wText = songView.songBtn.GetTextWidth() + Application.GetRealWidth(15);
                            if (wText > Application.GetRealWidth(280))
                            {
                                wText = Application.GetRealWidth(280);//(歌曲+歌手)宽度最大值时220
                            }
                            songView.songBtn.Width = wText;
                            songView.singerBtn.X = songView.songBtn.Right;
                            songView.singerBtn.Width = Application.GetRealWidth(280) - wText;//歌名长度小于220才可以显示歌手出来
                            songView.singerBtn.Text = string.IsNullOrEmpty(songs.Artist) ? "-Unkonw" : "-" + songs.Artist.Trim();
                            songView.clickBtn.Width = Application.GetRealWidth(344);
                            songView.clickBtn.Tag = i + 1;//标记播放哪一首歌曲
                        }
                        break;
                }
 
                //添加喜爱音乐控件
                songView.loveIcon.MouseUpEventHandler += (sender, e) =>
                {
                    songView.loveIcon.IsSelected = !songView.loveIcon.IsSelected;
                    if (songView.loveIcon.IsSelected)
                    {
                        ///查找音乐是否存在在列表
                        var music1 = A31MusicModel.Current.LoveMusicInfoList.Find((m) => m.URL == songs.URL);
                        if (music1 == null)
                        {
                            ///没有存在就添加
                            A31MusicModel.Current.LoveMusicInfoList.Add(songs);
                        }
                    }
                    else
                    {
                        ///查找音乐是否存在在列表
                        var music1 = A31MusicModel.Current.LoveMusicInfoList.Find((m) => m.URL == songs.URL);
                        if (music1 != null)
                        {
                            ///存在就删除
                            A31MusicModel.Current.LoveMusicInfoList.Remove(songs);
                        }
 
                        if (musicSource == "我的最爱")
                        {
                            songView.musicViewFl.RemoveFromParent();
                        }
 
                    }
                    A31MusicModel.Save();
                };
                //添加到我的列表
                songView.addIcon.MouseUpEventHandler = (sender, e) =>
                {
                    new HDL_ON.UI.Music.View.DialogView { }.FieListView(songs);
                };
                ///点击播放事件
                songView.clickBtn.MouseUpEventHandler += (sender, e) =>
                {
                    System.Threading.Tasks.Task.Run(() =>
                    {
                        System.Threading.Thread.Sleep(50);
                        Application.RunOnMainThread(() =>
                        {
                            //移除界面
                            A31MusicModel.Current.A31PlayStatus.Title = songView.songBtn.Text;
                            if (frame != null)
                            {
                                frame.RemoveFromParent();
                            }
                            MainPage.BasePageView.RemoveViewByTag("Music");
                            System.Threading.Tasks.Task.Run(() =>
                            {
                                if (musicSource == "本地音乐"|| musicSource == "我的最爱"|| musicSource == "我的列表")
                                {
                                    SendMethod.PushList(songs, listName, musicList, a31MusicModel,musicSource);
                                }
                                else if (musicSource == "USB"|| musicSource == "播放列表")
                                {
                                    SendMethod.ListMusicPlay(listName, songView.clickBtn.Tag, A31MusicModel.Current);
                                }
                            });
                        });
                    });
                };
 
            }
        }
    }
}