wxr
2022-09-27 0ee75b88cfe03e46289de0de96e8ed4580c797d3
HDL_ON/UI/UI2/FuntionControlView/Music/A31PlayMusicPage.cs
@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Security;
using HDL_ON.UI.UI2.FuntionControlView.Music;
using HDL_ON.Entity;
namespace HDL_ON.UI.Music
{
@@ -38,8 +39,6 @@
        /// </summary>
        View.PlayView playView = new View.PlayView();
        TopView topView;
        public void Show()
        {
@@ -90,34 +89,63 @@
            ///切换播放模式点击事件;
            playView.playOrderBtn.MouseUpEventHandler += (sender, e) =>
             {
                 string modeValueString = string.Empty;
                 string msg = Language.StringByID(StringId.switchTo);
                 string modeKeyValue = A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.mode);
                 switch (modeKeyValue)
                 //获取当前播放模式
                 string currModeKeyValue = A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.mode);
                 //获取音乐播放模式列表
                 var attributes = A31MusicModel.Current.functionMusic.GetAttribute(KeyProperty.mode);
                 if (attributes == null)
                 {
                     attributes = new FunctionAttributes();
                 }
                 var attributesList = attributes.value;
                 //找到当前播放模式索引值
                 int currModeIndexe = attributesList.IndexOf(currModeKeyValue);
                 //记录选中的播放模式的索引值
                 int count = 0;
                 if (currModeIndexe >= attributesList.Count - 1)
                 {
                     //重置索引值
                     count = 0;
                 }
                 else
                 {
                     count = currModeIndexe + 1;
                 }
                 //通过索引值找到模式value值
                 string modeValueString = attributesList[count];
                 switch (modeValueString)
                 {
                     //list_cycle列表循环,single_cycle单曲循环,random随机播放;
                     case ValueProperty.list_cycle:
                         modeValueString=ValueProperty.single_cycle;
                         playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/single.png";
                         msg += Language.StringByID(StringId.singleMode);
                         break;
                     case ValueProperty.single_cycle:
                         modeValueString =ValueProperty.random;
                         playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/random.png";
                         msg += Language.StringByID(StringId.randomMode);
                         break;
                     case ValueProperty.random:
                         modeValueString = ValueProperty.list_cycle;
                         playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/list.png";
                         msg += Language.StringByID(StringId.listMode);
                         break;
                     case ValueProperty.single_cycle:
                         playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/single_cycle.png";
                         msg += Language.StringByID(StringId.singleCycleMode);
                         break;
                     case ValueProperty.random:
                         playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/random.png";
                         msg += Language.StringByID(StringId.randomMode);
                         break;
                     case ValueProperty.single:
                         playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/single.png";
                         msg += Language.StringByID(StringId.single);
                         break;
                     case ValueProperty.order:
                         playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/order.png";
                         msg += Language.StringByID(StringId.orderMode);
                         break;
                 }
                 //写入缓存
                 A31MusicModel.Current.functionMusic.SetAttrState(KeyProperty.mode, modeValueString);
                 new PublicAssmebly().TipMsgAutoClose(msg, false,1000);
                 new PublicAssmebly().TipMsgAutoClose(msg, false, 1000);
                 Dictionary<string, string> dic = new Dictionary<string, string>();
                 dic.Add(KeyProperty.mode,modeValueString);
                 SendMethod.mMethod.SendControlCommand(A31MusicModel.Current.functionMusic,dic);
                 dic.Add(KeyProperty.mode, modeValueString);
                 //发送控制指令
                 SendMethod.Current.SendControlCommand(A31MusicModel.Current.functionMusic, dic);
             };
            ///添加喜爱点击事件;
            playView.loveBtn.MouseUpEventHandler += (sender, e) =>
@@ -164,7 +192,7 @@
                            A31MusicModel.Current.palyLists.Clear();
                            if (A31MusicModel.Current.palyLists.Count == 0)
                            {
                                SendMethod.mMethod.GetPalyList(A31MusicModel.Current.functionMusic);
                                SendMethod.Current.GetPalyList(A31MusicModel.Current.functionMusic);
                            }
                        }
@@ -184,7 +212,7 @@
                        }
                    });
                    //结束刷新
                };
                ///移除界面
                EventHandler<MouseEventArgs> removeFromParentView = (sen, e1) =>
@@ -205,10 +233,10 @@
            ///音量图标点击事件
            playView.volIconBtn.MouseUpEventHandler += (sender, e) =>
            {
            };
            ///音量进度条点击事件
            int startVolume =0;//之前的音量
            int startVolume = 0;//之前的音量
            //int endVolume = 0;//现在的音量
            EventHandler<int> progressClick = (sender, e) =>
            {
@@ -221,7 +249,7 @@
                    A31MusicModel.Current.functionMusic.SetAttrState(KeyProperty.volume, startVolume);
                    Dictionary<string, string> dic = new Dictionary<string, string>();
                    dic.Add(KeyProperty.volume, startVolume.ToString());
                    SendMethod.mMethod.SendControlCommand(A31MusicModel.Current.functionMusic, dic);
                    SendMethod.Current.SendControlCommand(A31MusicModel.Current.functionMusic, dic);
                }
            };
@@ -232,16 +260,16 @@
            {
                playView.prevBtn.IsSelected = true;
                A31MusicModel.Current.functionMusic.SetAttrState(KeyProperty.song_step,ValueProperty.down);
                A31MusicModel.Current.functionMusic.SetAttrState(KeyProperty.song_step, ValueProperty.down);
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add(KeyProperty.song_step, ValueProperty.up);
                SendMethod.mMethod.SendControlCommand(A31MusicModel.Current.functionMusic, dic);
                SendMethod.Current.SendControlCommand(A31MusicModel.Current.functionMusic, dic);
            };
            playView.prevBtn.MouseUpEventHandler += (sender, e) =>
            {
                playView.prevBtn.IsSelected = false;
            };
            };
            ///暂停/播放点击事件
            playView.playBtn.MouseDownEventHandler += (sender, e) =>
            {
@@ -250,7 +278,7 @@
                {
                    playView.playBtn.IsSelected = false;
                    status = ValueProperty.off;
                }
                else
                {
@@ -260,16 +288,16 @@
                A31MusicModel.Current.functionMusic.SetAttrState(KeyProperty.on_off, status);
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add(KeyProperty.on_off, status);
                SendMethod.mMethod.SendControlCommand(A31MusicModel.Current.functionMusic, dic);
                SendMethod.Current.SendControlCommand(A31MusicModel.Current.functionMusic, dic);
            };
            ///下一曲点击事件
            playView.nextBtn.MouseDownEventHandler += (sender, e) =>
            {
                playView.nextBtn.IsSelected = true;
                A31MusicModel.Current.functionMusic.SetAttrState(KeyProperty.song_step,ValueProperty.down);
                A31MusicModel.Current.functionMusic.SetAttrState(KeyProperty.song_step, ValueProperty.down);
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add(KeyProperty.song_step, ValueProperty.down);
                SendMethod.mMethod.SendControlCommand(A31MusicModel.Current.functionMusic, dic);
                SendMethod.Current.SendControlCommand(A31MusicModel.Current.functionMusic, dic);
            };
            playView.nextBtn.MouseUpEventHandler += (sender, e) =>
            {
@@ -318,22 +346,29 @@
                            int totalMusicMinute = totalSecond / 60;
                            //秒钟
                            int totalMusicSecond = totalSecond % 60;
                            //转化歌曲总时间时间格式
                            string totalTime = (totalMusicMinute.ToString().Length < 2 ? "0" + totalMusicMinute.ToString() : totalMusicMinute.ToString()) + ":" + (totalMusicSecond.ToString().Length < 2 ? "0" + totalMusicSecond.ToString() : totalMusicSecond.ToString());
                            //显示总时间
                            playView.endTimeBtn.Text = totalTime;
                            //显示播放器名称
                            topView.topNameBtn.Text = A31MusicModel.Current.functionMusic.name;
                            string s = A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.mode);
                            //显示播放模式图标
                            switch (A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.mode))
                            {
                                case ValueProperty.list_cycle://列表循环
                                    playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/list.png";
                                    break;
                                case ValueProperty.single_cycle://单曲循环
                                    playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/single.png";
                                    playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/single_cycle.png";
                                    break;
                                case ValueProperty.random://随机播放
                                    playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/random.png";
                                    break;
                                case ValueProperty.single:// 单曲<single>
                                    playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/single.png";
                                    break;
                                case ValueProperty.order://循序循环
                                    playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/order.png";
                                    break;
                            }
@@ -368,13 +403,17 @@
                            //        playView.loveBtn.IsSelected = false;
                            //    }
                            //}
                            //显示播放器区域
                            playView.regionBtn.Text = A31MusicModel.Current.functionMusic.GetRoomListName();
                            //显示播放器收藏状态
                            if (A31MusicModel.Current.functionMusic.collect)
                            {
                                //收藏
                                playView.collectIconBtn.IsSelected = true;
                            }
                            else
                            {
                                //不收藏
                                playView.collectIconBtn.IsSelected = false;
                            }
                            //if (A31MusicModel.Current.A31PlayStatus.IsMute)
@@ -394,9 +433,9 @@
                            //    }
                            //}
                            //为了防止音量条跳动,延长更新时间(多加1s)
                            if (2000 < (DateTime.Now - A31MusicModel.ProgressDateTime).TotalMilliseconds || A31MusicModel.ProgressDateTime==DateTime.MinValue)
                            if (2000 < (DateTime.Now - A31MusicModel.ProgressDateTime).TotalMilliseconds || A31MusicModel.ProgressDateTime == DateTime.MinValue)
                            {
                                //音量进度条;
                                //显示音量进度条值;
                                playView.volSeekBar.Progress = int.Parse(A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.volume));
                                //显示当前音量值;
                                playView.volValueBtn.Text = A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.volume) + "%";
@@ -410,17 +449,17 @@
                            if (A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.on_off) == ValueProperty.on)
                            {
                                //音乐在播放时,再计算播放时间(现在时间=原来时间+1秒)
                                playSecond +=(int)(DateTime.Now - A31MusicModel.Current.LastDateTime).TotalSeconds;
                                playSecond += (int)(DateTime.Now - A31MusicModel.Current.LastDateTime).TotalSeconds;
                                playSecond += 1;//表示加上等待的时间1s
                                ///歌曲记录暂时时间写入缓存;
                                A31MusicModel.Current.functionMusic.SetAttrState(KeyProperty.playing_time, playSecond);
                            }
                            if (playSecond<=0)
                            if (playSecond <= 0)
                            {
                                ///播放时间不能小于0;
                                playSecond = 0;
                            }
                            if (playSecond >=totalSecond)
                            if (playSecond >= totalSecond)
                            {
                                ///播放时间不能超过总时间;
                                playSecond = totalSecond;
@@ -428,39 +467,40 @@
                            int playMusicMinute = playSecond / 60;
                            //秒钟
                            int playMusicSecond = playSecond % 60;
                            //转化播放时间时间格式
                            string playTime = (playMusicMinute.ToString().Length < 2 ? "0" + playMusicMinute.ToString() : playMusicMinute.ToString()) + ":" + (playMusicSecond.ToString().Length < 2 ? "0" + playMusicSecond.ToString() : playMusicSecond.ToString());
                            //显示播放时间
                            playView.startTimeBtn.Text = playTime;
                            //显示播放状态
                            if (A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.on_off) == ValueProperty.on)
                            {
                                //播放
                                playView.playBtn.IsSelected = true;
                                //如果在播放,时间就不断变化
                                playView.startTimeBtn.Text = playTime;
                                if (totalSecond == 0)
                                {
                                    //歌曲进度条
                                    playView.diyArcSeekBar.Progress = 0;
                                }
                                else
                                {
                                    //歌曲进度条
                                    playView.diyArcSeekBar.Progress = (int)(playSecond * 100.0 / totalSecond);//+1
                                }
                            }
                            else
                            {
                                //暂停
                                playView.playBtn.IsSelected = false;
                                //停止播放
                                playView.startTimeBtn.Text =playTime;
                                //playView.startTimeBtn.Text ="00:00";
                                ///记录歌曲暂停时间;<LastDateTime 计算播放时间有用到>
                                A31MusicModel.Current.LastDateTime = DateTime.Now;
                            }
                            //显示进度条值
                            if (totalSecond == 0)
                            {
                                //歌曲播放进度
                                playView.diyArcSeekBar.Progress = 0;
                            }
                            else
                            {
                                //歌曲播放进度
                                playView.diyArcSeekBar.Progress = (int)(playSecond * 100.0 / totalSecond);//+1
                            }
                            //显示歌曲名称
                            playView.songNameTextView.Text = A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.song_name) == null ? "Unkown" : A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.song_name);
                            //显示歌手名称
                            playView.singerBtn.Text = A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.song_name) == null ? "Unkown" : A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.song_name);
                            //更新源的界面
                           // showSourcePage();
                            // showSourcePage();
                        }
                        catch (Exception e)
                        {
@@ -560,7 +600,9 @@
        void PlayListView(FrameLayout frameLayout, VerticalRefreshLayout verticalScrolViewLayout)
        {
            verticalScrolViewLayout.RemoveAll();
            //获取播放器名称
            var listName = A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.playlist_name);
            //获取缓存歌曲列表
            var musicList = A31MusicModel.Current.GetSongList(listName);
            if (musicList.Count == 0)
            {
@@ -571,7 +613,8 @@
                        A31MusicModel.Current.palyLists.Clear();
                        if (A31MusicModel.Current.palyLists.Count == 0)
                        {
                            SendMethod.mMethod.GetPalyList(A31MusicModel.Current.functionMusic);
                            //获取歌曲列表
                            SendMethod.Current.GetPalyList(A31MusicModel.Current.functionMusic);
                        }
                    }
@@ -600,8 +643,5 @@
        {
            UpdateThread.updateCurrMusicThread(frameLayout, middViewLayout, A31MusicModel.Current);
        }
    }
}