using System; using System.Collections.Generic; using System.Text; using Shared; using Shared.SimpleControl.Phone; using Shared.SimpleControl; using System.Xml; using Shared.SimpleControl.R; using System.Security; using SmartHome; using com.hdl.on; namespace Shared.SimpleControl.Phone.Music { /// /// 当前音乐播放界面 /// public class A31PlayMusicPage : FrameLayout { public A31PlayMusicPage() { Tag = "A31PlayMusicPage"; } void showSourcePage () { like.Alpha = 1; like.Enable = true; list.Alpha = 1; list.Enable = true; prev.Alpha = 1; prev.Enable = true; next.Alpha = 1; next.Enable = true; mode.Alpha = 1; mode.Enable = true; //btnPlay.Alpha = 1; //btnPlay.Enable = true; SeekBarVol.IsCanMove = true; switch (A31MusicModel.Current.A31PlayStatus.Source) { case "QPLAY"://QQ音乐 currentsource.UnSelectedImagePath = "MusicIcon/qqmusic1.png"; like.Alpha = 0.5f; like.Enable = false; break; case "AIRPLAY"://酷狗音乐 currentsource.UnSelectedImagePath = "MusicIcon/kumusic.png"; like.Alpha = 0.5f; like.Enable = false; SeekBarVol.IsCanMove = false; break; case "SONGLIST-NETWORK"://本地音乐 currentsource.UnSelectedImagePath = "MusicIcon/musicMusic1.png"; break; case "SONGLIST-LOCAL"://USB currentsource.UnSelectedImagePath = "MusicIcon/USB1.png"; break; case "RADIO-NETWORK"://在线电台 SeekBarVol.IsCanMove = false; currentsource.UnSelectedImagePath = "MusicIcon/local1.png"; list.Alpha = 1; list.Enable = true; prev.Alpha = 0.5f; prev.Enable = false; next.Alpha = 0.5f; next.Enable = false; mode.Alpha = 0.5f; mode.Enable = false; break; case "STATION-NETWORK"://Pandora电台 SeekBarVol.IsCanMove = false; currentsource.UnSelectedImagePath = "MusicIcon/pandora1.png"; like.Alpha = 0.5f; like.Enable = false; prev.Alpha = 0.5f; prev.Enable = false; mode.Alpha = 0.5f; mode.Enable = false; break; case "BLUETOOTH"://蓝牙 currentsource.UnSelectedImagePath = "MusicIcon/bluetooth1.png"; SeekBarVol.IsCanMove = false; like.Alpha = 0.5f; like.Enable = false; list.Alpha = 0.5f; list.Enable = false; prev.Alpha = 0.5f; prev.Enable = false; next.Alpha = 0.5f; next.Enable = false; mode.Alpha = 0.5f; mode.Enable = false; //btnPlay.Alpha = 0.5f; //btnPlay.Enable = false; break; case "LINE-IN"://线路输入 currentsource.UnSelectedImagePath = "MusicIcon/muiscline1.png"; SeekBarVol.IsCanMove = false; like.Alpha = 0.5f; like.Enable = false; list.Alpha = 0.5f; list.Enable = false; prev.Alpha = 0.5f; prev.Enable = false; next.Alpha = 0.5f; next.Enable = false; mode.Alpha = 0.5f; mode.Enable = false; //btnPlay.Alpha = 0.5f; //btnPlay.Enable = false; break; default: currentsource.UnSelectedImagePath = "MusicIcon/dlna.png"; SeekBarVol.IsCanMove = false; like.Alpha = 0.5f; like.Enable = false; list.Alpha = 0.5f; list.Enable = false; prev.Alpha = 0.5f; prev.Enable = false; next.Alpha = 0.5f; next.Enable = false; mode.Alpha = 0.5f; mode.Enable = false; break; } if (A31MusicModel.Current.A31PlayStatus.playSource == "UPnPServer") { currentsource.UnSelectedImagePath = "MusicIcon/dlna.png"; } else if (A31MusicModel.Current.A31PlayStatus.playSource == "Tidal") { currentsource.UnSelectedImagePath = "MusicIcon/Tidal1.png"; } } //public string Source { // set { // if (A31MusicModel.Current.A31PlayStatus.Source != value) { // A31MusicModel.Current.A31PlayStatus.Source = value; // sendCommand ("switchmode:" + value); // } // } //} /// /// 当前的源名称 /// Button a31sourceName; /// /// 下一曲 /// Button next; /// /// 上一曲 /// Button prev; /// /// 停止/播放 /// Button btnPlay; /// ///当前播放音乐时间 /// Button btnMusicplayTime; /// /// 音乐总时间 /// Button btnTotalMusicTime; /// /// 播放音乐时间进度条 /// //Button progressMaxButton; /// /// 播放进度 /// //Button progressButton; /// /// 歌名 /// TextView title; /// /// 静音图标 /// Button btnMute; Button btnMusicvol; /// /// 当前音量进度条 /// HorizontalSeekBar horizontalSeekBarVol; /// /// 快进进度条 /// HorizontalSeekBar SeekBarVol; /// /// 播放模式:0列表循环,1单曲循环,2随机播放 /// Button mode; /// /// 显示播放列表 /// Button list; /// /// 收藏图标 /// Button like; /// /// 当前音乐播放器的名称 /// Button setName; /// /// 歌手头像 /// Button musicartist; /// /// 当前播放源图标 /// Button currentsource; /// /// 当前歌手图像 /// ImageView portrait; /// /// 当前界面对象 /// static A31PlayMusicPage currentPlayMusic; FrameLayout middleFrameLayout = new FrameLayout (); public override void RemoveFromParent () { base.RemoveFromParent (); currentPlayMusic = null; isExit = true; timerThread?.Abort (); Volume.VolumeChange = null; } public void Show (List musicInfoList) { currentPlayMusic = this; A31MusicModel.Current.CurrentPlayMusicInfoList = musicInfoList; //读取当前的音乐状态 timerUpdateStatus (); AddChidren (new Button { Height = Application.GetRealHeight (30), BackgroundColor = SkinStyle.Current.MusicTopFrameLayout, }); var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight (100), Y = Application.GetRealHeight (30), BackgroundColor = SkinStyle.Current.MusicTopFrameLayout, }; AddChidren (topFrameLayout); setName = new Button { TextColor=SkinStyle.Current.MusicTextColor, }; topFrameLayout.AddChidren (setName); var back = new Button { Width = Application.GetMinRealAverage (72), Height = Application.GetMinRealAverage (89), X = Application.GetRealWidth (-1), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/PlayBack.png", }; topFrameLayout.AddChidren (back); back.MouseDownEventHandler += (sender, e) => { RemoveFromParent (); }; var set = new Button { Width = Application.GetRealWidth (76), Height = Application.GetRealHeight (66), X = Application.GetRealWidth (550), UnSelectedImagePath = "MusicIcon/PlayMusicset.png", Gravity = Gravity.CenterVertical, Tag = A31MusicModel.Current, }; topFrameLayout.AddChidren (set); set.MouseDownEventHandler += (sender, e) => { A31MusicSourcePage a31HomepageMusic = new A31MusicSourcePage (); MainPage.MainFrameLayout.AddChidren (a31HomepageMusic); a31HomepageMusic.Show ((A31MusicModel)set.Tag); }; middleFrameLayout.Width = LayoutParams.MatchParent; middleFrameLayout.Height = Application.GetRealHeight (1006 + 100); middleFrameLayout.Y = topFrameLayout.Bottom; middleFrameLayout.BackgroundImagePath = "MusicIcon/PlayBackgroun.png"; AddChidren (middleFrameLayout); //隐藏底层 topFrameLayout.BringToFront (); FrameLayout fra = new FrameLayout { Y = Application.GetRealHeight (155 - 130), Height = Application.GetRealHeight (106), }; middleFrameLayout.AddChidren (fra); like = new Button { Width = Application.GetRealWidth (106), Height = Application.GetRealHeight (103), X = Application.GetRealWidth (-2), UnSelectedImagePath = "MusicIcon/PlayLike.png", SelectedImagePath = "MusicIcon/PlayLikeSelected.png", Gravity = Gravity.CenterVertical, }; fra.AddChidren (like); like.MouseDownEventHandler += (sender, e) => { var url = A31MusicModel.Current.A31PlayStatus.TrackURL; var album = A31MusicModel.Current.A31PlayStatus.Album; var artist = A31MusicModel.Current.A31PlayStatus.Artist; if (A31MusicModel.Current.A31PlayStatus.Source == "RADIO-NETWORK") { like.IsSelected = !like.IsSelected; if (like.IsSelected) { if (null == A31MusicModel.Current.CnLoveRadioInfoList.Find ((musicInfo) => { return url == musicInfo.URL; })) { A31MusicModel.Current.CnLoveRadioInfoList.Add (new MusicInfo { Title = title.Text, URL = url, }); } } else { A31MusicModel.Current.CnLoveRadioInfoList.RemoveAll ((musicInfo) => { return url == musicInfo.URL; }); } A31MusicModel.Save (); } else if (A31MusicModel.Current.A31PlayStatus.playSource == "Tidal") { like.IsSelected = !like.IsSelected; if (like.IsSelected) { if (null == A31MusicModel.Current.TidalLikelist.Find ((musicInfo) => { return url == musicInfo.URL; })) { A31MusicModel.Current.TidalLikelist.Add (new MusicInfo { Title = title.Text, URL = url,Artist=artist }); } } else { A31MusicModel.Current.TidalLikelist.RemoveAll ((musicInfo) => { return url == musicInfo.URL; }); } A31MusicModel.Save (); } else { like.IsSelected = !like.IsSelected; if (like.IsSelected) { if (null == A31MusicModel.Current.LoveMusicInfoList.Find ((musicInfo) => { return url == musicInfo.URL; })) { A31MusicModel.Current.LoveMusicInfoList.Add (new MusicInfo { Title = title.Text, URL = url, Artist = artist, Album = album }); A31MusicModel.Save (); } } else { A31MusicModel.Current.LoveMusicInfoList.RemoveAll ((musicInfo) => { //也要加歌手名判断 return musicInfo.URL == url; }); A31MusicModel.Save (); } } //保存 string saveRoomUIName = "A31_" + A31MusicModel.Current.IPAddress; Shared.IO.FileUtils.WriteFileByBytes (saveRoomUIName, Shared.SimpleControl.CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (A31MusicModel.Current))); }; a31sourceName = new Button { Width = Application.GetRealWidth (200), Height = Application.GetRealHeight (60), X = Application.GetRealWidth (230), Gravity = Gravity.CenterVertical, }; fra.AddChidren (a31sourceName); currentsource = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), X = Application.GetRealWidth (640 - 61 - 1 - 20), Gravity = Gravity.CenterVertical, }; fra.AddChidren (currentsource); var color = new FrameLayout { Width = Application.GetMinRealAverage (330), Height = Application.GetMinRealAverage (330), Y = Application.GetRealHeight (290 - 130), BackgroundColor = 0x30FFFFFF, //BackgroundImagePath = "MusicIcon/PlayPortrait.png", //Animate= Animate.Rotation, Radius = (uint)Application.GetMinRealAverage (165), Gravity = Gravity.CenterHorizontal, }; middleFrameLayout.AddChidren (color); portrait = new ImageView { Width = Application.GetMinRealAverage (280), Height = Application.GetMinRealAverage (280), Radius = (uint)Application.GetMinRealAverage (140), Gravity = Gravity.Center, ImagePath = "MusicIcon/PlayPortrait.png", }; color.AddChidren (portrait); var frameLayout2 = new FrameLayout { Height = Application.GetRealHeight (103), Y = Application.GetRealHeight (730 - 130), }; middleFrameLayout.AddChidren (frameLayout2); mode = new Button { Width = Application.GetRealWidth (94), Height = Application.GetRealHeight (82), X = Application.GetRealWidth (1), Gravity = Gravity.CenterVertical, }; frameLayout2.AddChidren (mode); mode.MouseDownEventHandler += Mode_MouseDownEventHandler; title = new TextView { Width = Application.GetMinRealAverage (300), Height = Application.GetMinRealAverage (60), X = Application.GetRealWidth (170), Gravity = Gravity.CenterVertical, //Gravity = Gravity.Center, TextSize = 15, TextColor = SkinStyle.Current.MusicTextColor }; frameLayout2.AddChidren (title); musicartist = new Button { Width = Application.GetMinRealAverage (300), Height = Application.GetMinRealAverage (60), X = Application.GetRealWidth (170), Y = Application.GetRealHeight (790 - 130), //TextColor = 0x80ffffff, TextColor = SkinStyle.Current.MusicArtistTextColor }; middleFrameLayout.AddChidren (musicartist); list = new Button { Width = Application.GetRealWidth (106), Height = Application.GetRealHeight (103), X = Application.GetRealWidth (640 - 106 - 1), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/PlayList.png", Tag = A31MusicModel.Current.Name, }; frameLayout2.AddChidren (list); list.MouseUpEventHandler += (sender, e) => { A31PlayList listMusic = new A31PlayList (); MainPage.MainFrameLayout.AddChidren (listMusic); listMusic.InitFace (); MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { string PlayListName = "List"; string sourceName = "SourceName"; try { if (A31MusicModel.Current.A31PlayStatus.Source == "STATION-NETWORK") { A31MusicModel.Current.CurrentPlayMusicInfoList = new List (); return; } if (A31MusicModel.Current.A31PlayStatus.Source == "AIRPLAY") { A31MusicModel.Current.CurrentPlayMusicInfoList = new List (); return; } var playString = getCurrentPlayList (); A31MusicModel.Current.CurrentPlayMusicInfoList = new List (); var se = System.Security.SecurityElement.FromString (playString); while (se.Children != null) { se = se.Children [0] as System.Security.SecurityElement; } PlayListName = SecurityElement.FromString (se.Text).SearchForChildByTag ("ListName").Text; sourceName = SecurityElement.FromString (se.Text).SearchForChildByTag ("ListInfo").SearchForTextOfTag ("SourceName"); foreach (SecurityElement track in SecurityElement.FromString (se.Text).SearchForChildByTag ("Tracks").Children) { MusicInfo musicInfo = new MusicInfo (); musicInfo.URL = track.SearchForTextOfTag ("URL").Replace ("&", "&amp;"); var metadata = track.SearchForTextOfTag ("Metadata"); musicInfo.SourceName = track.SearchForTextOfTag ("Source"); if (string.IsNullOrEmpty (metadata)) { continue; } if (A31MusicModel.IsJson (metadata)) { var qqSong = Newtonsoft.Json.JsonConvert.DeserializeObject (metadata); musicInfo.Album = qqSong.album; musicInfo.Title = qqSong.title; musicInfo.Artist = qqSong.creator; } else { metadata = metadata.Replace ("", "").Replace ("&", "&amp;"); var item = SecurityElement.FromString (metadata).SearchForChildByTag ("item"); musicInfo.Title = item.SearchForTextOfTag ("dc:title"); musicInfo.Artist = item.SearchForTextOfTag ("upnp:artist"); musicInfo.Album = item.SearchForTextOfTag ("upnp:album"); musicInfo.Duration = item.SearchForTextOfTag ("res"); musicInfo.AlbumId = item.SearchForTextOfTag ("song:albumid"); } A31MusicModel.Current.CurrentPlayMusicInfoList.Add (musicInfo); } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); listMusic.Musiclist (PlayListName); }); } }); }; #region 歌曲时间 快,慢进度条 var tempFrameLayout3 = new FrameLayout { Height = Application.GetRealHeight (130), Y = Application.GetRealHeight (840 - 130), }; middleFrameLayout.AddChidren (tempFrameLayout3); btnMusicplayTime = new Button { Width = Application.GetRealWidth (126), Height = Application.GetRealHeight (126), X = Application.GetRealWidth (1), Gravity = Gravity.CenterVertical, }; tempFrameLayout3.AddChidren (btnMusicplayTime); btnTotalMusicTime = new Button { Width = Application.GetRealWidth (126), Height = Application.GetRealHeight (126), X = Application.GetRealWidth (640 - 1 - 126), Gravity = Gravity.CenterVertical, }; tempFrameLayout3.AddChidren (btnTotalMusicTime); var layout = new FrameLayout { X = Application.GetRealWidth (120), Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (50), Gravity = Gravity.CenterVertical, Radius = (uint)Application.GetRealHeight (25), }; tempFrameLayout3.AddChidren (layout); //快进进度条 SeekBarVol = new HorizontalSeekBar { Width = Application.GetRealWidth (400 - 26), Height = Application.GetRealHeight (50), Radius = (uint)Application.GetRealHeight (25), X = Application.GetRealWidth (13), Gravity = Gravity.CenterVertical, ProgressColor = 0xffFE5E00, SleepTime = 1000, ThumbRadius = 3, }; layout.AddChidren (SeekBarVol); SeekBarVol.MouseUpEventHandler += (sender, e) => { int totalSecond = (int)(SeekBarVol.Progress * 1.0f / SeekBarVol.Max * int.Parse (A31MusicModel.Current.A31PlayStatus.totlen) / 1000); //分钟 int Minute = totalSecond / 60; //秒钟 int Second = totalSecond % 60; string time = "00" + ":" + (Minute.ToString ().Length < 2 ? "0" + Minute.ToString () : Minute.ToString ()) + ":" + (Second.ToString ().Length < 2 ? "0" + Second.ToString () : Second.ToString ()); A31MusicModel.Current.Seek (time); A31MusicModel.Current.A31PlayStatus.curpos = (DateTime.Parse (time) - DateTime.Parse ("00:00:00")).TotalMilliseconds.ToString (); }; #endregion #region 上,下,暂停/播放 var tempFrameLayout = new FrameLayout { Height = Application.GetRealHeight (130), Y = Application.GetRealHeight (960 - 130), }; middleFrameLayout.AddChidren (tempFrameLayout); prev = new Button { Width = Application.GetMinRealAverage (126), Height = Application.GetMinRealAverage (126), X = Application.GetRealWidth (115), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/PlayPrve.png", SelectedImagePath = "MusicIcon/PlayPrveSelected.png", }; tempFrameLayout.AddChidren (prev); prev.MouseDownEventHandler += (sender, e) => { prev.IsSelected = true; A31MusicModel.Current.Previous (); //sendCommand ("prev"); }; prev.MouseUpEventHandler += (sender, e) => { prev.IsSelected = false; }; btnPlay = new Button { Width = Application.GetMinRealAverage (159), Height = Application.GetMinRealAverage (127), X = Application.GetRealWidth (241), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/Playplay.png", SelectedImagePath = "MusicIcon/playmusicplaySelected.png", }; tempFrameLayout.AddChidren (btnPlay); btnPlay.MouseDownEventHandler += (sender, e) => { if (btnPlay.IsSelected) { btnPlay.IsSelected = false; //sendCommand ("pause"); A31MusicModel.Current.Pause (); A31MusicModel.Current.A31PlayStatus.status = "pause"; } else { btnPlay.IsSelected = true; //sendCommand ("resume"); A31MusicModel.Current.Play (); A31MusicModel.Current.A31PlayStatus.status = "play"; } }; next = new Button { Width = Application.GetMinRealAverage (126), Height = Application.GetMinRealAverage (126), X = Application.GetRealWidth (400), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/PlayNext.png", SelectedImagePath = "MusicIcon/PlayNextSelected.png", }; tempFrameLayout.AddChidren (next); next.MouseDownEventHandler += (sender, e) => { next.IsSelected = true; A31MusicModel.Current.Next (); //sendCommand ("next"); }; next.MouseUpEventHandler += (sender, e) => { next.IsSelected = false; }; #endregion #region 静音, 音量+,-, btnMute = new Button { Width = Application.GetRealWidth (107), Height = Application.GetRealHeight (127), X = Application.GetRealWidth (1),//-2 Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/PlayMute.png", SelectedImagePath = "MusicIcon/PlayMuteSelected.png", }; tempFrameLayout.AddChidren (btnMute); int beforVol = 30; btnMute.MouseDownEventHandler += (sender, e) => { btnMute.IsSelected = !btnMute.IsSelected; if (btnMute.IsSelected) { A31MusicModel.Current.A31PlayStatus.vol = "0"; //记录之前的音量 beforVol = horizontalSeekBarVol.Progress; //sendCommand ("vol:0"); A31MusicModel.Current.ControlVolume (0); } else { A31MusicModel.Current.A31PlayStatus.vol = beforVol.ToString (); //sendCommand ("vol:" + beforVol); A31MusicModel.Current.ControlVolume (beforVol); } }; btnMusicvol = new Button { Width = Application.GetRealWidth (107), Height = Application.GetRealHeight (127), X = Application.GetRealWidth (640 - 1 - 107),//534 Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/PlayVoice.png", SelectedImagePath = "MusicIcon/PlayVoiceSelected.png", }; tempFrameLayout.AddChidren (btnMusicvol); btnMusicvol.MouseDownEventHandler += (sender, e) => { Button button = sender as Button; if (button.IsSelected) { button.IsSelected = false; middleFrameLayout.Y += Application.GetRealHeight (100); } else { button.IsSelected = true; middleFrameLayout.Y -= Application.GetRealHeight (100); } }; var ProgFrameLayout = new FrameLayout { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (100), Y = Application.GetRealHeight (1120 - 130), }; middleFrameLayout.AddChidren (ProgFrameLayout); var redbtnMusicvol = new Button { Width = Application.GetRealWidth (107), Height = Application.GetRealHeight (127), X = Application.GetRealWidth (1), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/redvol.png", SelectedImagePath = "MusicIcon/Selectedredvol.png", }; ProgFrameLayout.AddChidren (redbtnMusicvol); var addbtnMusicvo = new Button { Width = Application.GetRealWidth (107), Height = Application.GetRealHeight (127), X = Application.GetRealWidth (640 - 108), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/addvol.png", SelectedImagePath = "MusicIcon/Selectedaddvol.png", }; ProgFrameLayout.AddChidren (addbtnMusicvo); var frameLayout = new FrameLayout { Width = Application.GetRealWidth (460), Height = Application.GetRealHeight (50), Gravity = Gravity.CenterVertical, X = Application.GetRealWidth (90),//120 }; ProgFrameLayout.AddChidren (frameLayout); //当前播放的音量 horizontalSeekBarVol = new HorizontalSeekBar { Width = Application.GetRealWidth (460 - 26),//490 Height = Application.GetRealHeight (50), Radius = (uint)Application.GetRealHeight (25), X = Application.GetRealWidth (13), Gravity = Gravity.CenterVertical, ProgressColor = 0xffFE5E00, Max = 100, SleepTime = 1000, ThumbRadius = 9, //IsCanClick=false }; frameLayout.AddChidren (horizontalSeekBarVol); horizontalSeekBarVol.ProgressChanged += (sender, e) => { A31MusicModel.Current.ControlVolume (horizontalSeekBarVol.Progress); A31MusicModel.Current.A31PlayStatus.vol = horizontalSeekBarVol.Progress.ToString (); }; #endregion Volume.VolumeChange = (volume) => { if (Application.DeviceType == Device.Ios && A31MusicModel.Current.A31PlayStatus.Source == "BLUETOOTH") { return; } horizontalSeekBarVol.Progress = volume; A31MusicModel.Current.ControlVolume (horizontalSeekBarVol.Progress); A31MusicModel.Current.A31PlayStatus.vol = horizontalSeekBarVol.Progress.ToString (); }; //加音量 addbtnMusicvo.MouseUpEventHandler += (sen, e) => { addbtnMusicvo.IsSelected = false; var voladd = horizontalSeekBarVol.Progress + 1; if (voladd > 100) { voladd = 100; } A31MusicModel.Current.ControlVolume (voladd); A31MusicModel.Current.A31PlayStatus.vol = voladd.ToString (); horizontalSeekBarVol.Progress = voladd; }; addbtnMusicvo.MouseDownEventHandler += (sen, e) => { addbtnMusicvo.IsSelected = true; }; //减音量 redbtnMusicvol.MouseUpEventHandler += (sen, e) => { redbtnMusicvol.IsSelected = false; var volred = horizontalSeekBarVol.Progress - 1; if (volred < 0) { volred = 0; } A31MusicModel.Current.ControlVolume (volred); A31MusicModel.Current.A31PlayStatus.vol = volred.ToString (); horizontalSeekBarVol.Progress = volred; }; redbtnMusicvol.MouseDownEventHandler += (sen, e) => { redbtnMusicvol.IsSelected = true; }; } /// /// 获取当前播放的列表 /// string getCurrentPlayList () { StringBuilder getPlayList = new StringBuilder (); getPlayList.AppendLine (""); getPlayList.AppendLine (""); getPlayList.AppendLine (""); getPlayList.AppendLine (""); getPlayList.AppendLine ("CurrentQueue"); getPlayList.AppendLine (""); getPlayList.AppendLine (""); getPlayList.AppendLine (""); Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BrowseQueue\""); webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (getPlayList.ToString ())); return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length); } catch { } return null; } private void Mode_MouseDownEventHandler (object sender, MouseEventArgs e) { Button button = (Button)sender; switch (A31MusicModel.Current.A31PlayStatus.loop) { //0列表循环,1单曲循环,2随机播放; case "0": A31MusicModel.Current.A31PlayStatus.loop = "1"; button.UnSelectedImagePath = "MusicIcon/playModeDanquplay.png"; button.IsSelected = false; //new Tip() { Text = Language.StringByID(MyInternationalizationString.singlecycle), Direction = AMPopTipDirection.None }.Show(button); break; case "1": A31MusicModel.Current.A31PlayStatus.loop = "2"; button.UnSelectedImagePath = "MusicIcon/playModesuijiplay.png"; button.IsSelected = false; //new Tip() { Text = Language.StringByID(MyInternationalizationString.shuffleplay), Direction = AMPopTipDirection.None }.Show(button); break; case "2": A31MusicModel.Current.A31PlayStatus.loop = "0"; button.UnSelectedImagePath = "MusicIcon/playModeliebiaoplay.png"; button.IsSelected = false; //new Tip() { Text = Language.StringByID(MyInternationalizationString.circulationlisting), Direction = AMPopTipDirection.None }.Show(button); break; default: A31MusicModel.Current.A31PlayStatus.loop = "0"; button.UnSelectedImagePath = "MusicIcon/playModeliebiaoplay.png"; button.IsSelected = false; //new Tip() { Text = Language.StringByID(MyInternationalizationString.circulationlisting), Direction = AMPopTipDirection.None }.Show(button); break; } sendCommand ("loopmode:" + A31MusicModel.Current.A31PlayStatus.loop); } System.Threading.Thread timerThread; /// /// 是否已经退出 /// bool isExit = false; /// /// 定时更新状态 /// void timerUpdateStatus () { timerThread = new System.Threading.Thread ((obj) => { string album = null, artist = null; while (true) { if (SharedMethod.SharedMethod.IsBackground) { System.Threading.Thread.Sleep (1000 * 1); continue; } Application.RunOnMainThread (() => { try { #region 刷新歌手图片 if (A31MusicModel.Current.A31PlayStatus.Album != album || A31MusicModel.Current.A31PlayStatus.Artist != artist) { album = A31MusicModel.Current.A31PlayStatus.Album; artist = A31MusicModel.Current.A31PlayStatus.Artist; var path = "MusicImage/AlbumArtistImage_"; if (Shared.IO.FileUtils.Exists (path + A31MusicModel.Current.A31PlayStatus.Album)) { portrait.ImagePath = path + A31MusicModel.Current.A31PlayStatus.Album; } else if (Shared.IO.FileUtils.Exists (path + A31MusicModel.Current.A31PlayStatus.Artist)) { portrait.ImagePath = path + A31MusicModel.Current.A31PlayStatus.Artist; } else { portrait.ImagePath = "MusicIcon/PlayPortrait.png"; System.Threading.Tasks.Task.Run (() => { var filePath = Shared.IO.FileUtils.DownLoadImageFormBaidu (album, artist); if (filePath != null) { //Application.RunOnMainThread (() => { portrait.ImagePath = filePath; //}); } }); } } #endregion //更新总时间 //总共有多少秒 int totalSecond = int.Parse (A31MusicModel.Current.A31PlayStatus.totlen) / 1000; //分钟 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 ()); btnTotalMusicTime.Text = totalTime; setName.Text = A31MusicModel.Current.Name; switch (A31MusicModel.Current.A31PlayStatus.loop) { case "1"://单曲顺环 mode.UnSelectedImagePath = "MusicIcon/playModeDanquplay.png"; break; case "2"://随机播放 mode.UnSelectedImagePath = "MusicIcon/playModesuijiplay.png"; break; case "0"://列表循环 mode.UnSelectedImagePath = "MusicIcon/playModeliebiaoplay.png"; break; default: mode.UnSelectedImagePath = "MusicIcon/playModeliebiaoplay.png"; break; } if (A31MusicModel.Current.A31PlayStatus.Source == "RADIO-NETWORK") { var v = A31MusicModel.Current.CnLoveRadioInfoList.Find ((like) => { return like.Title == title.Text; }); if (v != null) { like.IsSelected = true; } else { like.IsSelected = false; } } else if (A31MusicModel.Current.A31PlayStatus.playSource == "Tidal") { var v = A31MusicModel.Current.TidalLikelist.Find ((like) => { return like.Title == title.Text; }); if (v != null) { like.IsSelected = true; } else { like.IsSelected = false; } } else { var v = A31MusicModel.Current.LoveMusicInfoList.Find ((like) => { return like.Title == title.Text; }); if (v != null) { like.IsSelected = true; } else { like.IsSelected = false; } } if (A31MusicModel.Current.A31PlayStatus.IsMute) { btnMute.IsSelected = true; horizontalSeekBarVol.Progress = 0; } else { btnMute.IsSelected = false; if (1000 < (DateTime.Now - A31MusicModel.ProgressDateTime).TotalMilliseconds) { horizontalSeekBarVol.Progress = int.Parse (A31MusicModel.Current.A31PlayStatus.vol); } } //更新播放器音量给系统音量 Volume.MusicVolume = horizontalSeekBarVol.Progress; Console.WriteLine (A31MusicModel.Current.Name + "播放音量:============" + A31MusicModel.Current.A31PlayStatus.vol); //当前播放音乐时间 int playSecond = int.Parse (A31MusicModel.Current.A31PlayStatus.curpos) / 1000;// + (int)(DateTime.Now - A31MusicModel.Current.LastDateTime).TotalSeconds; //currentMusiceA31.musicPalyTime = (playSecond*10).ToString(); //分钟 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 ()); if (A31MusicModel.Current.A31PlayStatus.status == "play") { btnPlay.IsSelected = true; //如果在播放,时间就不断变化 btnMusicplayTime.Text = playTime; if (totalSecond == 0) { SeekBarVol.Progress = 0; } else { SeekBarVol.Progress = (int)(playSecond * 100.0 / totalSecond);//+1 } } else { btnPlay.IsSelected = false; //停止播放 btnMusicplayTime.Text = "00:00"; } title.Text = (A31MusicModel.Current.A31PlayStatus.Title == null ? "Unkown" : A31MusicModel.Current.A31PlayStatus.Title); musicartist.Text = (A31MusicModel.Current.A31PlayStatus.Artist == null ? "Unkown" : A31MusicModel.Current.A31PlayStatus.Artist.Trim ()); //更新源的界面 showSourcePage (); } catch { } }); System.Threading.Thread.Sleep (1000 * 1); } }) { IsBackground = true }; timerThread.Start (); } void sendCommand (string coutn) { System.Threading.Tasks.Task.Run (() => { Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient(); try { byte [] recevieBytes1 = webClient.DownloadData (new Uri ("http://" + A31MusicModel.Current.IPAddress + "/httpapi.asp?command=setPlayerCmd:" + coutn)); } catch (Exception ex) { //this.IPAddress = ex.Message; } }); } } }