wjc
2023-02-03 c484347d42f8c14f03f498e689069a14a45abc93
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
using System;
using Shared;
using HDL_ON.UI.Music;
using System.Collections.Generic;
using HDL_ON.UI.UI2.FuntionControlView.Music;
 
namespace HDL_ON.UI.Music
{
 
    public class A31SongPlay : FrameLayout
    {
        public A31SongPlay()
        {
            Tag = "Music";
        }
 
 
        public void Show(SongList songLists)
        {
 
            this.BackgroundColor = MusicColor.ViewColor;
            var topView = new TopView();
            this.AddChidren(topView.TopFLayoutView());
            topView.topNameBtn.Text=songLists.group;
            topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
            var vv = new VerticalRefreshLayout
            {
                BackgroundColor = MusicColor.WhiteColor,
                Y = topView.fLayout.Bottom,
                Height = Application.GetRealHeight(H_W.H - H_W.T_Height),
            };
            this.AddChidren(vv);
            vv.BeginHeaderRefreshingAction += () =>
            {
                System.Threading.Tasks.Task.Run(() =>
                {
                    try
                    {
                        //获取歌曲列表
                        var songList = SendMethod.Current.GetSingleSongList(A31MusicModel.Current.functionMusic, songLists.group, songLists.source);
                        CommonMethod.Current.AddSongListMemory(songList, songLists.source);//保存缓存
                    }
                    catch
                    {
                    }
                    finally
                    {
                        Application.RunOnMainThread(() =>
                        {
                            vv.EndHeaderRefreshing();
                            //从缓存拿列表
                            var songListMemory = CommonMethod.Current.GetSongListMemory(songLists.group, songLists.source); 
                            ///加载音乐列表
                            SongListView(vv, songListMemory.songs, songListMemory.group, songLists.source);
                            
                        });
                    }
                });
            };
            ///加载音乐列表
            SongListView(vv, songLists.songs, songLists.group,songLists.source);
 
 
        }
        /// <summary>
        /// 加载音乐列表
        /// </summary>
        /// <param name="vv">父控件</param>
        /// <param name="musicList">音乐列表</param>
        /// <param name="listName">列表名</param>
        /// <param name="source">音乐源</param>
        public static void SongListView(VerticalRefreshLayout vv, List<SongInfo> musicList, string listName,string source, FrameLayout frame = null)
        {
            if (vv!=null) {
                vv.RemoveAll();
            }
            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(vv, songs);
                songView.songBtn.Text = songs.name;
                ///点击播放事件
                songView.clickBtn.MouseUpEventHandler += (sender, e) =>
                {
                    System.Threading.Tasks.Task.Run(() =>
                    {
                        System.Threading.Thread.Sleep(50);
                        Application.RunOnMainThread(() =>
                        {
                            //修改缓存属性状态值
                            A31MusicModel.Current.functionMusic.SetAttrState("song_name", songView.songBtn.Text);
                            A31MusicModel.Current.functionMusic.SetAttrState("playlist_name", listName);
                            //移除界面
                            if (frame != null)
                            {
                                frame.RemoveFromParent();
                            }
                            MainPage.BasePageView.RemoveViewByTag("Music");
                            Dictionary<string, string> dic = new Dictionary<string, string>();
                            dic.Add("song_name", songView.songBtn.Text);
                            dic.Add("playlist_name", listName);
                            if (!string.IsNullOrEmpty(songs.url))
                            {
                                dic.Add("url", songs.url);
                            }
                            if (!string.IsNullOrEmpty(source))
                            {
                                dic.Add("source", source);
                            }
                            SendMethod.Current.SendControlCommand(A31MusicModel.Current.functionMusic, dic);
                        });
                    });
                };
 
            }
 
        }
    }
 
    public class UpdateThread
    {
        public UpdateThread()
        {
        }
        /// <summary>
        /// 定时更新当前播放音乐
        /// </summary>
        /// <param name="frame">当前界面</param>
        /// <param name="middViewLayout">每一条音乐的主控件</param>
        /// <param name="a31MusicModel">点前播放器</param>
        public static void updateCurrMusicThread(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();
        }
 
    }
}