| | |
| | | { |
| | | #region 界面布局------ |
| | | |
| | | this.BackgroundColor = Color.ViewColor; |
| | | this.BackgroundColor = MusicColor.ViewColor; |
| | | var topView = new TopView(); |
| | | this.AddChidren(topView.TopFLayoutView()); |
| | | topView.topNameBtn.TextID = StringId.usb; |
| | | topView.clickBackBtn.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | |
| | | if (updateSelectedMusicThread != null) |
| | | { |
| | | try |
| | | { |
| | | if (updateSelectedMusicThread.IsAlive) |
| | | { |
| | | updateSelectedMusicThread.Abort(); |
| | | ///关闭线程 |
| | | } |
| | | } |
| | | catch { } |
| | | } |
| | | this.RemoveFromParent(); |
| | | }; |
| | | middViewLayout = new VerticalRefreshLayout |
| | | { |
| | | BackgroundColor = Color.WhiteColor, |
| | | BackgroundColor = MusicColor.WhiteColor, |
| | | Y = topView.fLayout.Bottom, |
| | | Height = Application.GetRealHeight(H_W.H - H_W.T_Height), |
| | | }; |
| | |
| | | public void Show() |
| | | { |
| | | middViewLayout.RemoveAll(); |
| | | int number = 0; |
| | | for (int i = 0; i < A31MusicModel.Current.USBList.Count; i++) |
| | | { |
| | | number++; |
| | | var songs = A31MusicModel.Current.USBList[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), |
| | | }; |
| | | middViewLayout.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 loveIcon = new Button |
| | | { |
| | | X = Application.GetRealWidth(291), |
| | | Y = Application.GetRealHeight(8), |
| | | Width = Application.GetMinRealAverage(28), |
| | | Height = Application.GetMinRealAverage(28), |
| | | UnSelectedImagePath = "MusicIcon/love.png", |
| | | SelectedImagePath = "MusicIcon/loveSelected.png", |
| | | }; |
| | | musicViewFl.AddChidren(loveIcon); |
| | | loveIcon.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | loveIcon.IsSelected = !loveIcon.IsSelected; |
| | | if (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); |
| | | } |
| | | |
| | | } |
| | | A31MusicModel.Save(); |
| | | }; |
| | | var music = A31MusicModel.Current.LoveMusicInfoList.Find((m) => m.URL == songs.URL); |
| | | if (music != null) |
| | | { |
| | | loveIcon.IsSelected = true; |
| | | } |
| | | else |
| | | { |
| | | loveIcon.IsSelected = false; |
| | | } |
| | | |
| | | //添加到我的列表 |
| | | Button addIcon = new Button |
| | | { |
| | | X = Application.GetRealWidth(335), |
| | | Y = Application.GetRealHeight(8), |
| | | Width = Application.GetMinRealAverage(28), |
| | | Height = Application.GetMinRealAverage(28), |
| | | UnSelectedImagePath = "MusicIcon/addMusic1.png", |
| | | }; |
| | | musicViewFl.AddChidren(addIcon); |
| | | addIcon.MouseUpEventHandler = (sender, e) => |
| | | { |
| | | new View.DialogView { }.FieListView(songs); |
| | | }; |
| | | |
| | | //点击控件 |
| | | Button clickBtn = new Button |
| | | { |
| | | Width = Application.GetRealWidth(280), |
| | | Height = Application.GetRealHeight(44), |
| | | Tag = number,//标记播放哪一首歌曲 |
| | | }; |
| | | musicViewFl.AddChidren(clickBtn); |
| | | ///点击播放事件 |
| | | clickBtn.MouseUpEventHandler += (sender, e) => |
| | | { |
| | | |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | | System.Threading.Thread.Sleep(50); |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | //移除界面 |
| | | A31MusicModel.Current.A31PlayStatus.Title = songBtn.Text; |
| | | MainPage.BasePageView.RemoveViewByTag("Music"); |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | | SendMethod.ListMusicPlay("USBDiskQueue", clickBtn.Tag,A31MusicModel.Current); |
| | | }); |
| | | }); |
| | | }); |
| | | |
| | | }; |
| | | |
| | | } |
| | | UI2.FuntionControlView.Music.UpdateThread.playMusuc(middViewLayout, "USB", "USBDiskQueue",A31MusicModel.Current.USBList, A31MusicModel.Current); |
| | | } |
| | | /// <summary> |
| | | /// 定时更新当前播放音乐 |
| | | /// </summary> |
| | | System.Threading.Thread updateSelectedMusicThread; |
| | | public void UpdateSelectedMusic() |
| | | { |
| | | 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 { } |
| | | |
| | | }); |
| | | } |
| | | }); |
| | | updateSelectedMusicThread.Start(); |
| | | } |
| | | /// <summary> |
| | | /// 数据封装 |
| | | /// </summary> |
| | | /// <param name="tag"></param> |
| | | void PlayStrinfg(object tag) |
| | | { |
| | | System.Text.StringBuilder sb = new System.Text.StringBuilder(); |
| | | sb.AppendLine("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"); |
| | | sb.AppendLine("<s:Body>"); |
| | | sb.AppendLine("<u:PlayQueueWithIndex xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">"); |
| | | sb.AppendLine("<QueueName>USBDiskQueue</QueueName>"); |
| | | sb.AppendLine("<Index>" + tag + "</Index>"); |
| | | sb.AppendLine("</u:PlayQueueWithIndex>"); |
| | | sb.AppendLine("</s:Body>"); |
| | | sb.AppendLine("</s:Envelope>"); |
| | | |
| | | Paly(sb.ToString()); |
| | | } |
| | | /// <summary> |
| | | /// 播放命令 |
| | | /// </summary> |
| | | /// <param name="s"></param> |
| | | void Paly(string s) |
| | | { |
| | | |
| | | System.Net.WebClient webClient = new System.Net.WebClient(); |
| | | webClient.Headers.Add("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#PlayQueueWithIndex\""); |
| | | webClient.Headers.Add("CONTENT-TYPE", "text/xml;charset=\"utf-8\""); |
| | | try |
| | | { |
| | | byte[] bytes = webClient.UploadData(new Uri("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(s)); |
| | | var ab = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length); |
| | | } |
| | | catch { } |
| | | UI2.FuntionControlView.Music.UpdateThread.updateThread(this, middViewLayout, A31MusicModel.Current); |
| | | } |
| | | |
| | | } |