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() { } /// /// 定时更新当前播放音乐 /// /// 当前界面 /// 每一条音乐的主控件 /// 点前播放器 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(); } /// /// 播放音乐 /// /// 上下拉动父控件 /// 音乐源 /// 播放列表名 /// 播放音乐列表 /// 音乐播放器 public static void playMusuc(VerticalRefreshLayout middViewLayout, string musicSource, string listName,List 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); } }); }); }); }; } } } }