陈嘉乐
2020-07-31 52e317b95d830f8cd1156b403ff5a34fb8f9bccb
HDL_ON/UI/UI2/FuntionControlView/Music/A31PlayMusicPage.cs
@@ -8,9 +8,15 @@
{
    public class A31PlayMusicPage : FrameLayout
    {
        /// <summary>
        /// 当前对象构造函数
        /// </summary>
        public A31PlayMusicPage()
        {
        }
        /// <summary>
        /// 重写RemoveFromParent方法
        /// </summary>
        public override void RemoveFromParent()
        {
            base.RemoveFromParent();
@@ -28,6 +34,9 @@
            }
        }
        /// <summary>
        /// new布局界面
        /// </summary>
        View.PlayView playView = new View.PlayView();
      
        public void Show()
@@ -76,8 +85,8 @@
            };
            #endregion
            //快进滑动事件;
            EventHandler<int> seekClick = (sender, e) =>
            //快进滑动弹起事件;
            playView.diyArcSeekBar.OnStopTrackingTouchEvent+= (sender, e) =>
            {
                int totalSecond = (int)(playView.diyArcSeekBar.Progress * 1.0f / 100 * int.Parse(A31MusicModel.Current.A31PlayStatus.totlen) / 1000);
                //分钟
@@ -88,9 +97,6 @@
                SendMethod.Seek(time, A31MusicModel.Current);
                A31MusicModel.Current.A31PlayStatus.curpos = (DateTime.Parse(time) - DateTime.Parse("00:00:00")).TotalMilliseconds.ToString();
            };
            //playView.diyArcSeekBar.OnProgressChangedEvent += seekClick;
            playView.diyArcSeekBar.OnStopTrackingTouchEvent += seekClick;//快进滑动不发命令,
            ///切换播放模式点击事件;
            playView.playOrderBtn.MouseUpEventHandler += (sender, e) =>
             {
@@ -178,115 +184,22 @@
            {
                #region  布局界面---
                Loading loading = new Loading();
                FrameLayout popFra = new FrameLayout()
                UI2.FuntionControlView.Music.View.MyListView myListView = new UI2.FuntionControlView.Music.View.MyListView();
                myListView.frameLayout(this, A31MusicModel.Current);
                myListView.dialogFra.AddChidren(loading);//dialogFra刷新图标父控件
                ///下拉刷新
                myListView.verticalScrolViewLayout.BeginHeaderRefreshingAction += () =>
                {
                    BackgroundColor = Color.PopupBackgroundColor,
                    //结束刷新
                    myListView.verticalScrolViewLayout.EndHeaderRefreshing();
                };
                this.AddChidren(popFra);
                FrameLayout dialogFra = new FrameLayout()
                {
                    X = Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(187),
                    Width = Application.GetRealWidth(344),
                    Height = Application.GetRealHeight(460),
                    BackgroundColor = Color.WhiteColor,
                    Radius = (uint)Application.GetRealHeight(12),
                };
                popFra.AddChidren(dialogFra);
                dialogFra.AddChidren(loading);//dialogFra刷新图标父控件
                FrameLayout topFra = new FrameLayout()
                {
                    Width = Application.GetRealWidth(344),
                    Height = Application.GetRealHeight(50),
                };
                dialogFra.AddChidren(topFra);
                Button orderIconBtn = new Button
                {
                    X = Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(11),
                    Width = Application.GetMinRealAverage(28),
                    Height = Application.GetMinRealAverage(28),
                };
                topFra.AddChidren(orderIconBtn);
                Button orderTxetBtn = new Button
                {
                    X = Application.GetRealWidth(60),
                    Y = Application.GetRealHeight(14),
                    Width = Application.GetRealWidth(120),
                    Height = Application.GetRealHeight(22),
                    TextColor = Color.TextColor,
                    TextSize = TextSize.Text16,
                    TextAlignment = TextAlignment.CenterLeft,
                };
                topFra.AddChidren(orderTxetBtn);
                switch (A31MusicModel.Current.A31PlayStatus.loop)
                {
                    //0列表循环,1单曲循环,2随机播放;
                    case "0":
                        orderIconBtn.UnSelectedImagePath = "MusicIcon/list.png";
                        orderTxetBtn.Text = Language.StringByID(StringId.listMode);
                        break;
                    case "1":
                        orderIconBtn.UnSelectedImagePath = "MusicIcon/single.png";
                        orderTxetBtn.Text = Language.StringByID(StringId.singleMode);
                        break;
                    case "2":
                        orderIconBtn.UnSelectedImagePath = "MusicIcon/random.png";
                        orderTxetBtn.Text = Language.StringByID(StringId.randomMode);
                        break;
                }
                Button backIextBtn = new Button
                {
                    X = Application.GetRealWidth(288),//300
                    Y = Application.GetRealHeight(15),
                    Width = Application.GetRealWidth(28 + 12),//28
                    Height = Application.GetRealHeight(20),
                    TextID = StringId.cancelMusic,
                    TextColor = Color.MusicNoTxetColor,
                    TextSize = TextSize.Text14,
                    TextAlignment = TextAlignment.CenterLeft,
                };
                topFra.AddChidren(backIextBtn);
                Button lineBtn = new Button
                {
                    Y = topFra.Height - 1,
                    Width = Application.GetRealWidth(344),
                    Height = H_W.Line,
                    BackgroundColor = Color.LineColor,
                };
                topFra.AddChidren(lineBtn);
                VerticalScrolViewLayout verticalScrolViewLayout = new VerticalScrolViewLayout
                {
                    Y = Application.GetRealHeight(50),
                    Height = Application.GetRealHeight(410),
                    Width = Application.GetRealWidth(344),
                };
                dialogFra.AddChidren(verticalScrolViewLayout);
                ///移除界面
                EventHandler<MouseEventArgs> removeFromParentView = (sen, e1) =>
                 {
                     if (updateSelectedMusicThread != null)
                     {
                         try
                         {
                             if (updateSelectedMusicThread.IsAlive)
                             {
                                 updateSelectedMusicThread.Abort();
                                 ///关闭线程
                             }
                         }
                         catch { }
                     }
                     popFra.RemoveFromParent();
                     myListView.popFra.RemoveFromParent();
                 };
                backIextBtn.MouseUpEventHandler += removeFromParentView;
                popFra.MouseUpEventHandler += removeFromParentView;
                myListView.backIextBtn.MouseUpEventHandler += removeFromParentView;
                myListView.popFra.MouseUpEventHandler += removeFromParentView;
                #endregion
                loading.Start();
                System.Threading.Tasks.Task.Run(() =>
@@ -350,8 +263,8 @@
                        Application.RunOnMainThread(() =>
                        {
                            loading.Hide();
                            PlayListView(popFra, verticalScrolViewLayout, playListName);
                            UpdateSelectedMusic(verticalScrolViewLayout);
                            PlayListView(myListView.popFra, myListView.verticalScrolViewLayout, playListName);
                            UpdateSelectedMusic(myListView.popFra, myListView.verticalScrolViewLayout);
                        });
                    }
                });
@@ -363,7 +276,6 @@
                if (A31MusicModel.Current.ServerClientType == 1 && A31MusicModel.Current.Slave.slave_list.Count != 0)
                { ///主播放器
                   //new View.DialogView { }.PlayerVolumeView(A31MusicModel.Current);
                    var volumeView = new View.DialogView { };
                    volumeView.PlayerVolumeView(A31MusicModel.Current);
                    volumeView.UpdateVolume();
@@ -440,7 +352,9 @@
            };
        }
        /// <summary>
        /// 定义全局线程
        /// </summary>
        System.Threading.Thread timerThread;
        /// <summary>
        /// 定时更新状态
@@ -744,7 +658,7 @@
        /// 显示当前播放音乐View
        /// </summary>
        /// <param name="verticalScrolViewLayout"></param>
        void PlayListView(FrameLayout frameLayout, VerticalScrolViewLayout verticalScrolViewLayout, string playListName)
        void PlayListView(FrameLayout frameLayout, VerticalRefreshLayout verticalScrolViewLayout, string playListName)
        {
            verticalScrolViewLayout.RemoveAll();
            int number = 0;
@@ -752,106 +666,15 @@
            {
                number++;
                var songs = A31MusicModel.Current.CurrentPlayMusicInfoList[i];
                if (string.IsNullOrEmpty(songs.Title))
                {
                    //防止歌曲名字为空抛异常
                    songs.Title = " ";
                }
                if (string.IsNullOrEmpty(songs.Artist))
                {
                    //防止歌手名字为空抛异常
                    songs.Artist = " ";
                }
                FrameLayout musicViewFl = new FrameLayout
                {
                    Width = Application.GetRealWidth(375),
                    Height = Application.GetRealHeight(44),
                };
                verticalScrolViewLayout.AddChidren(musicViewFl);
                //列表当前播放音乐图标
                Button playIconBtn = new Button
                {
                    X = Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(10),
                    Width = Application.GetMinRealAverage(24),
                    Height = Application.GetMinRealAverage(24),
                    UnSelectedImagePath = "MusicIcon/playStatus.png",
                    Visible = false,
                    Name = "playStatus",
                    Tag = songs.URL,
                };
                musicViewFl.AddChidren(playIconBtn);
                //歌曲控件
                Button songBtn = new Button
                {
                    X = Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(11),
                    Width = Application.GetRealWidth(100),
                    Height = Application.GetRealHeight(22),
                    TextColor = Color.MusicTxet14Color,
                    TextSize = TextSize.Text16,
                    TextAlignment = TextAlignment.CenterLeft,
                    Name = "song",
                    Tag = songs.URL,
                    Text = songs.Title.Trim()
                };
                musicViewFl.AddChidren(songBtn);
                var wText = songBtn.GetTextWidth();//获取文本宽度
                ///(歌曲+歌手)宽度最大值时280
                if (wText > 280)
                {
                    songBtn.Width = Application.GetRealWidth(280);
                }
                else
                {
                    songBtn.Width = wText + 5;
                }
                //歌手控件
                Button singerBtn = new Button
                {
                    X = songBtn.Right,
                    Y = Application.GetRealHeight(11),
                    Width = Application.GetRealWidth(280 - songBtn.Width),
                    Height = Application.GetRealHeight(22),
                    TextColor = Color.MusicNoTxetColor,
                    TextSize = TextSize.Text12,
                    TextAlignment = TextAlignment.CenterLeft,
                    //Text =("-" +songs.Artist).Trim(),
                    Name = "singer",
                    Tag = songs.URL,
                    Text = "-" + songs.Artist.Trim()
                };
                musicViewFl.AddChidren(singerBtn);
                if (wText > 280)
                {
                    ///歌名长度小于250才可以显示歌手出来
                    singerBtn.Width = Application.GetRealWidth(0);
                }
                //点击控件
                Button clickBtn = new Button
                {
                    Width = Application.GetRealWidth(280),
                    Height = Application.GetRealHeight(44),
                    Tag = number,//标记播放哪一首歌曲
                };
                musicViewFl.AddChidren(clickBtn);
                View.SongView songView = new View.SongView();
                songView.SongFrameLayout(verticalScrolViewLayout, songs);
                songView.loveIcon.Visible = false;
                songView.addIcon.Visible = false;
                songView.clickBtn.Width = Application.GetRealWidth(344);
                songView.clickBtn.Tag = number;//标记播放哪一首歌曲
                ///点击播放事件
                clickBtn.MouseUpEventHandler += (sender, e) =>
                songView.clickBtn.MouseUpEventHandler += (sender, e) =>
                {
                    if (updateSelectedMusicThread != null)
                    {
                        try
                        {
                            if (updateSelectedMusicThread.IsAlive)
                            {
                                updateSelectedMusicThread.Abort();
                                ///关闭线程
                            }
                        }
                        catch { }
                    }
                    System.Threading.Tasks.Task.Run(() =>
                    {
                        System.Threading.Thread.Sleep(50);
@@ -859,10 +682,10 @@
                        {
                            //移除界面
                            frameLayout.RemoveFromParent();
                            A31MusicModel.Current.A31PlayStatus.Title = songBtn.Text;
                            A31MusicModel.Current.A31PlayStatus.Title = songView.songBtn.Text;
                            System.Threading.Tasks.Task.Run(() =>
                            {
                                SendMethod.ListMusicPlay(playListName, clickBtn.Tag, A31MusicModel.Current);
                                SendMethod.ListMusicPlay(playListName, songView.clickBtn.Tag, A31MusicModel.Current);
                            });
                        });
                    });
@@ -874,51 +697,9 @@
        /// <summary>
        /// 定时更新当前播放音乐
        /// </summary>
        System.Threading.Thread updateSelectedMusicThread;
        void UpdateSelectedMusic(VerticalScrolViewLayout middViewLayout)
        void UpdateSelectedMusic(FrameLayout frameLayout, VerticalRefreshLayout middViewLayout)
        {
            updateSelectedMusicThread = new System.Threading.Thread(() =>
            {
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(1000);
                    Application.RunOnMainThread(() =>
                    {
                        try
                        {
                            for (int i = 0; i < middViewLayout.ChildrenCount; i++)
                            {
                                FrameLayout view = (FrameLayout)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.Current.A31PlayStatus.TrackURL == songNameBtn.Tag.ToString())
                                {
                                    volIconBtn.Visible = true;
                                    songNameBtn.TextColor = Color.SelectedColor;
                                    songNameBtn.X = Application.GetRealWidth(48);
                                    artistNameBtn.X = songNameBtn.Right;
                                    artistNameBtn.TextColor = Color.SelectedColor;
                                }
                                else
                                {
                                    volIconBtn.Visible = false;
                                    songNameBtn.TextColor = Color.MusicTxet14Color;
                                    songNameBtn.X = Application.GetRealWidth(16);
                                    artistNameBtn.X = songNameBtn.Right;
                                    artistNameBtn.TextColor = Color.MusicNoTxetColor;
                                }
                            }
                        }
                        catch { }
                    });
                }
            })
            { IsBackground = true };
            updateSelectedMusicThread.Start();
            UI2.FuntionControlView.Music.UpdateThread.updateThread(frameLayout, middViewLayout, A31MusicModel.Current);
        }
    }
}