HDL_ON/Common/ApiUtlis.cs
@@ -157,6 +157,7 @@ if (deviceResult.Code == StateCode.SUCCESS) { endTime = DateTime.Now.AddSeconds(100); MainPage.Log($"读取设备信息成功"); var deviceList = Newtonsoft.Json.JsonConvert.DeserializeObject<DevcieApiPack>(deviceResult.Data.ToString()); if (deviceList == null) @@ -369,8 +370,6 @@ if (DB_ResidenceData.Instance.CurrentRegion != null) { #region 读取本地数据 //读取音乐信息 UI.Music.A31MusicModel.ReadMusicStates(); //搜索网关 DriverLayer.Control.Ins.SearchLoaclGateway(); //重新连接mqtt HDL_ON/DAL/DriverLayer/Control.cs
@@ -979,21 +979,35 @@ var localFunction = allLocalFuntion.Find((obj) => obj.sid == updateTemp.sid); if (localFunction == null) { Console.WriteLine("找不到音乐播放器添=======" + revString); continue; } if (Ins.GatewayOnline_Local && isCloudData)//本地链接,除了涂鸦设备数据之外的云端数据不处理 { if (!SPK.Get3tySpk(SPK.BrandType.All3tyBrand).Contains(localFunction.spk)) if (!SPK.Get3tySpk(SPK.BrandType.All3tyBrand).Contains(localFunction.spk) && !SPK.MusicSpkList().Contains( localFunction.spk)) { //MainPage.Log($"A协议更新状态:本地链接,除了涂鸦设备数据之外的云端数据不处理........"); return; } } //if (SPK.MusicSpkList().Contains(localFunction.spk)) //{ // if (updateTemp.status.Count < 3) // { // ///是音乐功能的 // ///上报属性少3条不做处理 // return; // } //} //MainPage.Log($"A协议更新状态:{revString}"); foreach (var attr in updateTemp.status) { localFunction.time_stamp = temp.time_stamp; localFunction.SetAttrState(attr.key, attr.value); Console.WriteLine("音乐播放器添加缓存数据=======" + revString); } //更新界面状态 @@ -1175,6 +1189,12 @@ //状态更新 Stan.HdlDeviceStatuPushLogic.Current.UpdateDeviceStatu(updateTemp.sid, updateTemp.status); break; case SPK.AvMusic: case SPK.MusicStandard: //UI.Music.MusicMain.mMusicMain.RefreshView(updateTemp); Console.WriteLine("音乐播放器显示状态======="+ revString); //wjc break; } HomePage.UpdataFunctionStates(localFunction); HDL_ON/DAL/Server/NewAPI.cs
@@ -739,6 +739,12 @@ /// </summary> public const string Api_Post_BindSourcePanel = "/home-wisdom/source/screen/home/bind"; #region ■ -- 音乐相关接口_______________________________ /// <summary> /// 获取音乐列表 /// </summary> public const string Api_Post_PlayerList = "/home-wisdom/app/wise/music/playerList"; #endregion } HDL_ON/HDL_ON.projitems
@@ -60,31 +60,6 @@ <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\ArmSensor\SensorSmokePage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\ArmSensor\SensorPirPage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\ArmSensor\ArmSensorHistroyPaging.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\MusicMain.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31Radio.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\UpdateThread.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31RadioList.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31MusicModel.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31MusicSourcePage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31PlayMusicPage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31LoveRadioList.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31LoveList.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31USBMusicList.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31PlayStatus.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31MyList.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\SendMethod.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31LocalMusicList.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31LoveMusicList.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31MyListMusic.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\DialogView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\TopView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\MusicView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\PlayView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\SizeClass.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\TipView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\MusicSourceView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\SongView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\MyListView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Electrical\TuyaFanPage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Electrical\ClothesHangerPage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Electrical\FanPage.cs" /> @@ -491,6 +466,26 @@ <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Electrical\SocketPage_InstantaneousValue.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Electrical\SocketPage_CumulativePowerConsumption.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\4-PersonalCenter\CancelAccountPage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\MusicMain.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31MusicModel.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31MusicSourcePage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31PlayMusicPage.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31MyList.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\SendMethod.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31LoveMusicList.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31MyListMusic.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\DialogView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\TopView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\MusicView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\PlayView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\SizeClass.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\TipView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\MusicSourceView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\SongView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\View\MyListView.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31MusicFileList.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\A31SongPlay.cs" /> <Compile Include="$(MSBuildThisFileDirectory)UI\UI2\FuntionControlView\Music\MusicProperty.cs" /> </ItemGroup> <ItemGroup> <Folder Include="$(MSBuildThisFileDirectory)Entity\Device\" /> HDL_ON/UI/UI0-Public/PublicAssmeblyBLL.cs
@@ -125,7 +125,7 @@ break; case SPK.MusicStandard: case SPK.AvMusic: Music.A31MusicModel.Current = (function as Music.A31MusicModel);//当前播放器 Music.A31MusicModel.Current.functionMusic =function;//当前播放器 var a31PlayMusicPage = new Music.A31PlayMusicPage(); MainPage.BasePageView.AddChidren(a31PlayMusicPage); a31PlayMusicPage.Show(); HDL_ON/UI/UI2/1-HomePage/HomePage.cs
@@ -856,29 +856,29 @@ if (SPK.MusicSpkList().Contains( function.spk)) { //var music = function as Music.A31MusicModel; var music = Music.A31MusicModel.A31MusicModelList.Find((obj) => obj.sid == function.sid); if (music == null) { continue; } if (music.ServerClientType == -1) { continue; } else if (music.ServerClientType == 1) { if (!music.MainPlayCollection) { continue; } } else { if (!music.collect) { continue; } } //var music = Music.A31MusicModel.A31MusicModelList.Find((obj) => obj.sid == function.sid); //if (music == null) //{ // continue; //} //if (music.ServerClientType == -1) //{ // continue; //} //else if (music.ServerClientType == 1) //{ // if (!music.MainPlayCollection) // { // continue; // } //} //else //{ // if (!music.collect) // { // continue; // } //} } else { @@ -1197,8 +1197,8 @@ SelectedImagePath = "FunctionIcon/Music/MusicPlayOnIcon.png", }; view.AddChidren(btnPower); var a31player = (function as UI.Music.A31MusicModel); btnState.Text = a31player.A31PlayStatus.Title; btnState.Text = function.GetAttrState("song_name"); btnState.SelectedTextColor = CSS_Color.MainBackgroundColor; btnState.TextColor = CSS_Color.MainBackgroundColor;//PromptingColor1 @@ -1207,21 +1207,22 @@ btnPower.MouseUpEventHandler = (sender, e) => { string status = "off"; if (btnPower.IsSelected) { btnPower.IsSelected = false; Music.SendMethod.Pause(a31player); a31player.A31PlayStatus.status = "pause"; a31player.trait_on_off.curValue = "off"; status = "off"; } else { btnPower.IsSelected = true; Music.SendMethod.Play(a31player); a31player.A31PlayStatus.status = "play"; a31player.trait_on_off.curValue = "on"; status = "on"; } UpdataFunctionStates(a31player); function.SetAttrState("on_off", status); Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("on_off", status); Music.SendMethod.mMethod.SendControlCommand(function, dic); }; } @@ -1279,14 +1280,14 @@ //取消收藏事件 Action cannelCollect = () => { function.collect = false; if (SPK.MusicSpkList().Contains(function.spk))//处理音乐主从关系 { if ((function as Music.A31MusicModel).ServerClientType == 1) { (function as Music.A31MusicModel).MainPlayCollection = false; Music.A31MusicModel.Save(); } } //if (SPK.MusicSpkList().Contains(function.spk))//处理音乐主从关系 //{ // if ((function as Music.A31MusicModel).ServerClientType == 1) // { // (function as Music.A31MusicModel).MainPlayCollection = false; // Music.A31MusicModel.Save(); // } //} string msg = function.name + Language.StringByID(StringId.CollectionCancelled); LoadDeviceFunctionControlZone(); function.CollectFunction(); HDL_ON/UI/UI2/1-HomePage/HomePageBLL.cs
@@ -244,11 +244,11 @@ function.collect = false; if (SPK.MusicSpkList().Contains(function.spk))//处理音乐主从关系 { if ((function as Music.A31MusicModel).ServerClientType == 1) { (function as Music.A31MusicModel).MainPlayCollection = false; Music.A31MusicModel.Save(); } //if ((function as Music.A31MusicModel).ServerClientType == 1) //{ // (function as Music.A31MusicModel).MainPlayCollection = false; // Music.A31MusicModel.Save(); //} } string msg = function.name + Language.StringByID(StringId.CollectionCancelled); LoadDeviceFunctionControlZone(); @@ -374,7 +374,7 @@ { if (SPK.MusicSpkList().Contains(function.spk)) { btn.Text = (function as Music.A31MusicModel).A31PlayStatus.Title; btn.Text =function.GetAttrState("song_name"); } else { HDL_ON/UI/UI2/2-Classification/ClassificaitionPublicBLL.cs
@@ -156,12 +156,12 @@ else if (SPK.MusicSpkList().Contains(updataFunction.spk)) { #region 音乐更新 var uMusic = updataFunction as Music.A31MusicModel; var uMusic = updataFunction; if (cTag == updataFunction.spk + "_State_" + updataFunction.sid) { try { (fcView.GetChildren(j) as Button).IsSelected = uMusic.A31PlayStatus.status == "play"; (fcView.GetChildren(j) as Button).IsSelected = uMusic.GetAttrState("on_off") == "on"; } catch (Exception ex) { HDL_ON/UI/UI2/2-Classification/ClassificationPageBLL.cs
@@ -214,9 +214,12 @@ foreach (var m in Music.A31MusicModel.A31MusicModelList) { if (m.roomIds.Contains(room.roomId)) if (m.functionMusic.roomIds.Contains(room.roomId)) { Music.SendMethod.Pause(m); m.functionMusic.SetAttrState("on_off", "off"); Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("on_off", "off"); Music.SendMethod.mMethod.SendControlCommand(m.functionMusic, dic); } } }) HDL_ON/UI/UI2/2-Classification/FunctionControlZone.cs
@@ -408,7 +408,7 @@ SelectedImagePath = "MusicIcon/nextSelected.png", }; bodyDiv.AddChidren(btnNext); LoadEvent_ControlMusic(btnPlay, btnNext, btnPrev, function as A31MusicModel); LoadEvent_ControlMusic(btnPlay, btnNext, btnPrev, function); #endregion } HDL_ON/UI/UI2/2-Classification/FunctionControlZoneBLL.cs
@@ -291,7 +291,7 @@ /// <param name="btnOpen"></param> /// <param name="btnClose"></param> /// <param name="curtain"></param> void LoadEvent_ControlMusic(Button btnPlay,Button btnNext,Button btnPrev, A31MusicModel a31player) void LoadEvent_ControlMusic(Button btnPlay,Button btnNext,Button btnPrev, Function a31player) { if (a31player == null) return; @@ -299,7 +299,10 @@ btnPrev.MouseDownEventHandler = (sender, e) => { btnPrev.IsSelected = true; SendMethod.Previous(a31player); a31player.SetAttrState("song_step", "up"); Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("song_step", "up"); SendMethod.mMethod.SendControlCommand(a31player, dic); }; btnPrev.MouseUpEventHandler = (sender, e) => { @@ -308,24 +311,30 @@ ///暂停/播放点击事件 btnPlay.MouseDownEventHandler = (sender, e) => { string status = "off"; if (btnPlay.IsSelected) { btnPlay.IsSelected = false; SendMethod.Pause(a31player); a31player.A31PlayStatus.status = "pause"; status = "off"; } else { btnPlay.IsSelected = true; SendMethod.Play(a31player); a31player.A31PlayStatus.status = "play"; status = "on"; } a31player.SetAttrState("on_off", status); Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("on_off", status); SendMethod.mMethod.SendControlCommand(a31player, dic); }; ///下一曲点击事件 btnNext.MouseDownEventHandler = (sender, e) => { btnNext.IsSelected = true; SendMethod.Next(a31player); a31player.SetAttrState("song_step", "down"); Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("song_step", "down"); SendMethod.mMethod.SendControlCommand(a31player, dic); }; btnNext.MouseUpEventHandler = (sender, e) => { HDL_ON/UI/UI2/3-Intelligence/Automation/PublicInterface.cs
@@ -682,7 +682,7 @@ case "time": { list = new List<string> { "30 s", //"30 s", "1 min", "2 min", "3 min", HDL_ON/UI/UI2/FuntionControlView/Music/A31LocalMusicList.cs
File was deleted HDL_ON/UI/UI2/FuntionControlView/Music/A31LoveList.cs
File was deleted HDL_ON/UI/UI2/FuntionControlView/Music/A31LoveMusicList.cs
@@ -49,14 +49,14 @@ public void MusicView(string listName) { middViewLayout.RemoveAll(); UI2.FuntionControlView.Music.UpdateThread.playMusuc(middViewLayout, "我的最爱", listName, A31MusicModel.Current.LoveMusicInfoList, A31MusicModel.Current); //UpdateThread.PlayMusicClick(middViewLayout, "我的最爱", listName, A31MusicModel.Current.LoveMusicInfoList); } /// <summary> /// 定时更新当前播放音乐 /// </summary> public void UpdateSelectedMusic() { UI2.FuntionControlView.Music.UpdateThread.updateThread(this, middViewLayout,A31MusicModel.Current); UpdateThread.updateCurrMusicThread(this, middViewLayout,A31MusicModel.Current); } HDL_ON/UI/UI2/FuntionControlView/Music/A31LoveRadioList.cs
File was deleted HDL_ON/UI/UI2/FuntionControlView/Music/A31MusicFileList.cs
New file @@ -0,0 +1,115 @@ using System; using System.Collections.Generic; using Shared; namespace HDL_ON.UI.Music { public class A31MusicFileList : FrameLayout { public A31MusicFileList() { Tag = "Music"; } VerticalRefreshLayout middViewLayout; public void Show() { #region 界面布局------ this.BackgroundColor = MusicColor.ViewColor; var topView = new TopView(); this.AddChidren(topView.TopFLayoutView()); topView.topNameBtn.TextID = StringId.localMusic; topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); }; middViewLayout = new VerticalRefreshLayout { BackgroundColor = MusicColor.WhiteColor, Y = topView.fLayout.Bottom, Height = Application.GetRealHeight(H_W.H - H_W.T_Height), }; this.AddChidren(middViewLayout); #endregion middViewLayout.BeginHeaderRefreshingAction += () => { System.Threading.Tasks.Task.Run(() => { try { SendMethod.mMethod.GetPalyList(A31MusicModel.Current.functionMusic); } catch { } finally { Application.RunOnMainThread(() => { this.FileView(); middViewLayout.EndHeaderRefreshing(); }); } }); }; } /// <summary> /// 加载文件夹View的方法 /// </summary> public void FileView() { middViewLayout.RemoveAll(); for (int i = 0; i < A31MusicModel.Current.palyLists.Count; i++) { var list = A31MusicModel.Current.palyLists[i]; RowLayout addFlieRow = new RowLayout { Height = Application.GetRealHeight(104), LineColor = MusicColor.WhiteColor, SubViewWidth = Application.GetRealWidth(90),//改变编辑控件宽度多少; }; middViewLayout.AddChidren(addFlieRow); //文件图标 Button fileIconBtn = new Button { X = Application.GetRealWidth(16), Y = Application.GetRealHeight(8), Width = Application.GetRealWidth(88), Height = Application.GetRealWidth(88), UnSelectedImagePath = "MusicIcon/fileList.png", }; addFlieRow.AddChidren(fileIconBtn); //文件名控件 Button fileNameBtn = new Button { X = fileIconBtn.Right + Application.GetRealWidth(16), Y = Application.GetRealHeight(42), Width = Application.GetRealWidth(217), Height = Application.GetRealHeight(20), TextColor = MusicColor.TextColor, TextSize = TextSize.Text14, TextAlignment = TextAlignment.CenterLeft, Text = list.group, }; addFlieRow.AddChidren(fileNameBtn); Button clickBtn = new Button { X = fileIconBtn.Right + Application.GetRealWidth(16), Width = Application.GetRealWidth(375 - 138), Height = Application.GetRealHeight(104), }; addFlieRow.AddChidren(clickBtn); clickBtn.MouseUpEventHandler += (sender, e) => { A31SongPlay a31Song = new A31SongPlay(); MainPage.BasePageView.AddChidren(a31Song); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; a31Song.Show(list.songs, list.group); }; } } } } HDL_ON/UI/UI2/FuntionControlView/Music/A31MusicModel.cs
@@ -7,88 +7,22 @@ { [System.Serializable] public class A31MusicModel : Function public class A31MusicModel { public static List<A31MusicModel> A31MusicModelList = new List<A31MusicModel> { }; static readonly string a31MusiceModeListFilePath = "A31MusiceModeListFilePath"; static A31MusicModel() { Refresh(); //Refresh(); } static List<System.Threading.Thread> updataMusicStatesListThread = new List<System.Threading.Thread>(); /// <summary> /// 读取音乐状态 /// 音乐功能 /// </summary> public static void ReadMusicStates() { RemoveListThread(); if (GetCollection) { for (int i = 0; i < A31MusicModelList.Count; i++) { var a31player = A31MusicModelList[i]; var musicThread = new System.Threading.Thread(() => { while (true) { System.Threading.Thread.Sleep(1000); if (!a31player.IsOnLine) { continue; } SendMethod.ReadStatus(a31player); } }) { IsBackground = true, Name = "A31" }; musicThread.Start(); updataMusicStatesListThread.Add(musicThread); } } } /// <summary> /// 移除之前的线程 /// </summary> public static void RemoveListThread() { for (int i = 0; i < updataMusicStatesListThread.Count;) { try { var thread = updataMusicStatesListThread[i]; if (thread.IsAlive) { thread.Abort(); } updataMusicStatesListThread.Remove(thread); } catch (Exception e) { MainPage.Log("clearA31Threads error : " + e.Message); } finally { MainPage.Log("clearA31Threads over"); } } } /// <summary> /// 音乐列表里是否有音乐被收藏过 /// </summary> static bool GetCollection { get { for (int i = 0; i < A31MusicModelList.Count; i++) { if (A31MusicModelList[i].collect) { return true; //查询是否有音乐被收藏过 } } return false; } } public Function functionMusic = new Function(); /// <summary> ///保存当前音乐列表 /// </summary> @@ -116,51 +50,27 @@ A31MusicModelList.RemoveAll((obj) => obj == null); } /// <summary> /// 音乐播放器名称 /// </summary> public string Name = string.Empty; /// <summary> /// 上一次更新的时间 /// 记录数据反馈的时间(因为有时间网络差数据不回复,导致刷新当前播放音乐时间不正确) /// ((当前时间)DateTime.Now - (记录时间)LastDateTimeLastDateTime).TotalSeconds=误差时间(秒) /// </summary> public DateTime LastDateTime; /// <summary> /// IP地址 /// </summary> public string IPAddress = "192.168.1.100"; /// <summary> /// 端口 /// </summary> public int Port = 49153; /// <summary> /// 是否是播放器列表最后一个(true) /// </summary> public bool IsEnd = false; public int A31DeviceType; //public string a31Source = "wifi"; //public string a31Source = string.Empty; /// <summary> /// 音乐播放器ID /// </summary> public string UniqueDeviceName = string.Empty; /// <summary> /// 当前播放状态 /// </summary> public A31PlayStatus A31PlayStatus = new A31PlayStatus(); public MusicInfo CurrentMusic = new MusicInfo(); /// <summary> ///当前播放的列表信息 /// </summary> public List<MusicInfo> CurrentPlayMusicInfoList = new List<MusicInfo>(); public List<Songs> CurrentPlayMusicInfoList = new List<Songs>(); /// <summary> /// 是否允许显示 @@ -168,47 +78,15 @@ public bool IsCanShow = true; /// <summary> /// 是否在线,如果在线就允许读取信息 /// 列表 /// </summary> public bool IsOnLine = true; public List<PalyList> palyLists = new List<PalyList>(); /// <summary> /// 喜爱音乐列表 /// </summary> public List<MusicInfo> LoveMusicInfoList = new List<MusicInfo>(); public List<Songs> LoveMusicInfoList = new List<Songs>(); /// <summary> /// DLNA所有列表 /// </summary> public List<MusicInfo> dlnaMusicInfoLists = new List<MusicInfo>(); /// <summary> /// 电台所有列表 /// </summary> public List<MusicInfo> CnRadioInfoList = new List<MusicInfo>(); /// <summary> /// vTuner电台所有列表 /// </summary> public List<MusicInfo> vTunerList = new List<MusicInfo>(); /// <summary> /// 喜爱电台列表 /// </summary> public List<MusicInfo> LoveRadioInfoList = new List<MusicInfo>(); /// <summary> /// Pandora电台所有列表 /// </summary> public List<MusicInfo> PanRadioInfoList = new List<MusicInfo>(); /// <summary> /// usb列表 /// </summary> public List<MusicInfo> USBList = new List<MusicInfo>(); /// <summary> /// Tidal喜爱列表 /// </summary> public List<MusicInfo> TidalLikelist = new List<MusicInfo>(); /// <summary> ///创建音乐文件列表 /// </summary> @@ -218,53 +96,22 @@ /// </summary> public static A31MusicModel Current; public int _ServerClientType; /// <summary> /// -1表示从的0表示默认1表示主的 /// </summary> public int ServerClientType { get { return _ServerClientType; } set { _ServerClientType = value; if(value == 0) { name = Name; } } } /// <summary> /// 记录主播放器IP /// </summary> public string MainPlayIP = string.Empty; public string _MainPlayName = string.Empty; /// <summary> /// 记录主播放器名称 /// 指定列表名获取音乐列表 /// </summary> public string MainPlayName /// <returns></returns> public List<Songs> GetSongList(string listName) { get { return _MainPlayName; var list = palyLists.Find((o)=>o.group==listName); if (list==null) { return new List<Songs>(); } set { _MainPlayName = value; if(ServerClientType == 1) { name = value; } } return list.songs; } /// <summary> /// 记录主播放器是否被收藏(秀桡定义的) /// </summary> public bool MainPlayCollection = false; public Slaves Slave = new Slaves(); /// <summary> @@ -272,6 +119,11 @@ /// </summary> public static DateTime ProgressDateTime = DateTime.Now; /// <summary> /// 判断是否是json数据 /// </summary> /// <param name="json"></param> /// <returns></returns> public static bool IsJson(string json) { try @@ -310,7 +162,7 @@ /// <summary> /// 列表歌曲信息 /// </summary> public List<MusicInfo> MusicInfoList = new List<MusicInfo>(); public List<Songs> MusicInfoList = new List<Songs>(); } [System.Serializable] public class TidalMusicInfo : MusicInfo @@ -340,4 +192,61 @@ public string uuid = string.Empty; } [System.Serializable] /// <summary> /// 支持多个音乐 /// </summary> public class PalyListInfo { /// <summary> /// 音乐sid /// </summary> public string sid = string.Empty; /// <summary> /// 解释多个音乐 /// </summary> public List<PalyList> playlist = new List<PalyList>(); } [System.Serializable] /// <summary> /// 列表信息 /// </summary> public class PalyList { /// <summary> /// 列表名 /// </summary> public string group = string.Empty; /// <summary> /// 列表歌曲信息 /// </summary> public List<Songs> songs = new List<Songs>(); } [System.Serializable] public class Songs:MusicInfo { /// <summary> /// 歌曲名称 /// </summary> public string name = string.Empty; /// <summary> /// 大小 /// </summary> public string size = string.Empty; /// <summary> /// 时长 /// </summary> public string time = string.Empty; /// <summary> /// 类型<自己用> /// </summary> public string type = string.Empty; } } HDL_ON/UI/UI2/FuntionControlView/Music/A31MusicSourcePage.cs
@@ -33,7 +33,7 @@ #region 基础信息( 播放器 蓝牙 区域) FrameLayout fL1 = new FrameLayout { Height = Application.GetRealHeight(202), Height = Application.GetRealHeight(202-50), Width = Application.GetRealWidth(375), }; middViewLayout.AddChidren(fL1); @@ -50,17 +50,11 @@ View.MusicSourceView playNameView = new View.MusicSourceView(); playNameView.fLayout.Y = musicIfonView.fLayout.Bottom; playNameView.textBtn.TextID = StringId.playerName; playNameView.inputTextBtn.Text = A31MusicModel.Current.Name; playNameView.inputTextBtn.Text = A31MusicModel.Current.functionMusic.name; playNameView.FrameLayoutView(fL1, false); View.MusicSourceView bluetoothNameView = new View.MusicSourceView(); bluetoothNameView.fLayout.Y = playNameView.fLayout.Bottom; bluetoothNameView.textBtn.TextID = StringId.bluetoothName; bluetoothNameView.inputTextBtn.Text = A31MusicModel.Current.Name; bluetoothNameView.FrameLayoutView(fL1, false); View.MusicSourceView areaText = new View.MusicSourceView(); areaText.fLayout.Y = bluetoothNameView.fLayout.Bottom; areaText.fLayout.Y = playNameView.fLayout.Bottom; areaText.FrameLayoutView(fL1, false); areaText.nextLevelBtn.X = Application.GetRealWidth(339); areaText.nextLevelBtn.Y = Application.GetRealHeight(17); @@ -70,7 +64,7 @@ areaText.lineBtn.BackgroundColor = MusicColor.WhiteColor; areaText.textBtn.X = Application.GetRealWidth(16); areaText.textBtn.TextID = StringId.region; areaText.inputTextBtn.Text = A31MusicModel.Current.GetRoomListName(); areaText.inputTextBtn.Text = A31MusicModel.Current.functionMusic.GetRoomListName(); #endregion @@ -80,7 +74,7 @@ Height = Application.GetRealHeight(152), Width = Application.GetRealWidth(375), }; middViewLayout.AddChidren(fL2); //middViewLayout.AddChidren(fL2); View.MusicSourceView playListView = new View.MusicSourceView(); playListView.fLayout.Height = Application.GetRealHeight(44); @@ -122,41 +116,25 @@ selectedSourceView.nextLevelBtn.Visible = false; selectedSourceView.FrameLayoutView(fL3, false); View.MusicSourceView localMusicSourceView = new View.MusicSourceView(); localMusicSourceView.fLayout.Y = selectedSourceView.fLayout.Bottom; localMusicSourceView.iconBtn.UnSelectedImagePath = "MusicIcon/localMusic.png"; localMusicSourceView.textBtn.TextID = StringId.localMusic; localMusicSourceView.FrameLayoutView(fL3); View.MusicSourceView musicSourceView = new View.MusicSourceView(); musicSourceView.fLayout.Y = selectedSourceView.fLayout.Bottom; musicSourceView.iconBtn.UnSelectedImagePath = "MusicIcon/localMusic.png"; musicSourceView.textBtn.TextID = StringId.localMusic; musicSourceView.FrameLayoutView(fL3); View.MusicSourceView usbSourceView = new View.MusicSourceView(); usbSourceView.fLayout.Y = localMusicSourceView.fLayout.Bottom; usbSourceView.iconBtn.UnSelectedImagePath = "MusicIcon/usb.png"; usbSourceView.textBtn.TextID = StringId.usb; usbSourceView.FrameLayoutView(fL3); View.MusicSourceView radioSourceView = new View.MusicSourceView(); radioSourceView.fLayout.Y = usbSourceView.fLayout.Bottom; radioSourceView.iconBtn.UnSelectedImagePath = "MusicIcon/radio.png"; radioSourceView.textBtn.TextID = StringId.radio; //radioSourceView.FrameLayoutView(fL3);暂时隐藏在线电台 View.MusicSourceView qqMusicSourceView = new View.MusicSourceView(); qqMusicSourceView.fLayout.Y = usbSourceView.fLayout.Bottom; qqMusicSourceView.iconBtn.UnSelectedImagePath = "MusicIcon/qqMusic.png"; qqMusicSourceView.textBtn.TextID = StringId.qqMusic; qqMusicSourceView.FrameLayoutView(fL3); View.MusicSourceView bluetoothSourceView = new View.MusicSourceView(); bluetoothSourceView.fLayout.Y = qqMusicSourceView.fLayout.Bottom; bluetoothSourceView.fLayout.Y = musicSourceView.fLayout.Bottom; bluetoothSourceView.iconBtn.UnSelectedImagePath = "MusicIcon/bluetooth.png"; bluetoothSourceView.textBtn.TextID = StringId.bluetooth; bluetoothSourceView.FrameLayoutView(fL3); //bluetoothSourceView.FrameLayoutView(fL3); View.MusicSourceView lineSourceView = new View.MusicSourceView(); lineSourceView.fLayout.Y = bluetoothSourceView.fLayout.Bottom; lineSourceView.iconBtn.UnSelectedImagePath = "MusicIcon/line.png"; lineSourceView.textBtn.TextID = StringId.line; lineSourceView.FrameLayoutView(fL3); //lineSourceView.FrameLayoutView(fL3); #endregion @@ -164,34 +142,69 @@ #endregion #region 所有点击事件 ///事件 musicSourceView.clickBtn.MouseUpEventHandler += (sender, e) => { A31MusicFileList a31MusicFileList = new A31MusicFileList(); MainPage.BasePageView.AddChidren(a31MusicFileList); a31MusicFileList.Show(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; Loading loading = new Loading(); a31MusicFileList.AddChidren(loading); loading.Start(); System.Threading.Tasks.Task.Run(() => { try { if (A31MusicModel.Current.palyLists.Count == 0) { SendMethod.mMethod.GetPalyList(A31MusicModel.Current.functionMusic); } } catch { } finally { Application.RunOnMainThread(() => { loading.Hide(); a31MusicFileList.FileView(); }); } }); }; ///播放器修改名称事件 playNameView.clickBtn.MouseUpEventHandler += (sender, e) => { new View.TipView().InputBox(StringId.modifyName, A31MusicModel.Current.Name, StringId.nameNull, (playerName) => new View.TipView().InputBox(StringId.modifyName, A31MusicModel.Current.functionMusic.name, StringId.nameNull, (playerName) => { playNameView.inputTextBtn.Text = playerName; A31MusicModel.Current.Name = playerName; string url = "http://" + A31MusicModel.Current.IPAddress + "/httpapi.asp?command=setDeviceName:" + A31MusicModel.Current.Name; SendMethod.SendCommand(url); A31MusicModel.Current.functionMusic.name = playerName; //发送命令 System.Threading.Tasks.Task.Run(() => { try { SendMethod.mMethod.EditDeviceName(A31MusicModel.Current.functionMusic.deviceId,playerName); } catch { } }); }); }; ///蓝牙修改名称事件 bluetoothNameView.clickBtn.MouseUpEventHandler += (sender, e) => { new View.TipView().InputBox(StringId.modifyName, A31MusicModel.Current.Name, StringId.nameNull, (bluetoothName) => { bluetoothNameView.inputTextBtn.Text = bluetoothName; SendMethod.ModifyBluetoothName("MCU+PAS+BT" + bluetoothName.Trim() + "*&"); }); }; ///区域修改的事件 areaText.clickBtn.MouseUpEventHandler += (sender, e) => { ChooseRoomPage chooseRoomPage = new ChooseRoomPage(A31MusicModel.Current, () => ChooseRoomPage chooseRoomPage = new ChooseRoomPage(A31MusicModel.Current.functionMusic, () => { areaText.inputTextBtn.Text = A31MusicModel.Current.GetRoomListName(); areaText.inputTextBtn.Text = A31MusicModel.Current.functionMusic.GetRoomListName(); A31MusicModel.Save(); }); MainPage.BasePageView.AddChidren(chooseRoomPage); @@ -223,117 +236,19 @@ a31MyList.UpdateSelectedFile(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; ///本地音乐事件 localMusicSourceView.clickBtn.MouseUpEventHandler += (sender, e) => { A31LocalMusicList a31LocalMusicList = new A31LocalMusicList(); MainPage.BasePageView.AddChidren(a31LocalMusicList); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; a31LocalMusicList.Show(); a31LocalMusicList.UpdateSelectedMusic(); }; ///USB事件 usbSourceView.clickBtn.MouseUpEventHandler += (sender, e) => { A31USBMusicList usbMusic = new A31USBMusicList(); MainPage.BasePageView.AddChidren(usbMusic); usbMusic.UIView(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; Loading loading = new Loading(); usbMusic.AddChidren(loading); loading.Start(); System.Threading.Tasks.Task.Run(() => { try { if (A31MusicModel.Current.USBList.Count == 0) { //进来读一次(注意:播放地址可能会改变,导致播放不了音乐;解决:进来都去去读取最新数据) var list = SendMethod.GetUsbList(A31MusicModel.Current); A31MusicModel.Current.USBList.AddRange(list); } } catch { } finally { Application.RunOnMainThread(() => { loading.Hide(); usbMusic.Show(); usbMusic.UpdateSelectedMusic(); }); } }); }; ///在线电台事件 radioSourceView.clickBtn.MouseUpEventHandler += (sender, e) => { Loading loading = new Loading(); this.AddChidren(loading); loading.Start(); System.Threading.Tasks.Task.Run(() => { var radioList = SendMethod.ReadRadioList("http://opml.radiotime.com/Browse.ashx?partnerId=yvcOjvJP"); Application.RunOnMainThread(() => { loading.Hide(); A31Radio a31Radio = new A31Radio(); MainPage.BasePageView.AddChidren(a31Radio); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; a31Radio.Show(radioList); }); }); }; ///QQ音乐事件 qqMusicSourceView.clickBtn.MouseUpEventHandler += (sender, e) => { //string str = "com.tencent.qqmusic"; //if (Application.DeviceType == Device.Ios) //{ // str = "qqmusic:"; //} //CommonClass.OpenApp(str); bool bol = false; string url = ""; try { #if __IOS__ bol = HDLUtils.OpenApp("qqmusic://"); url = "https://apps.apple.com/cn/app/qq%E9%9F%B3%E4%B9%90-%E8%AE%A9%E7%94%9F%E6%B4%BB%E5%85%85%E6%BB%A1%E9%9F%B3%E4%B9%90/id414603431"; #else bol = HDLUtils.OpenAppWithPackageName("com.tencent.qqmusic"); //url = "http://music.qq.com/"; url = "market://details?id=com.tencent.qqmusic"; #endif if (!bol) { new View.TipView().TipBox1(StringId.tip, StringId.qqMsuicTip, () => { HDLUtils.OpenUrl(url); }); } } catch { } }; ///蓝牙事件 bluetoothSourceView.clickBtn.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); string url = "http://" + A31MusicModel.Current.IPAddress + "/httpapi.asp?command=setPlayerCmd:switchmode:bluetooth"; SendMethod.SendCommand(url); }; ///线路输入事件 lineSourceView.clickBtn.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); string url = "http://" + A31MusicModel.Current.IPAddress + "/httpapi.asp?command=setPlayerCmd:switchmode:line-in"; SendMethod.SendCommand(url); }; HDL_ON/UI/UI2/FuntionControlView/Music/A31MyList.cs
@@ -101,71 +101,7 @@ UnSelectedImagePath = "MusicIcon/fileList.png", }; addFlieRow.AddChidren(fileIconBtn); //播放/暂停图标 Button playIconBtn = new Button { X = Application.GetRealWidth(78), Y = Application.GetRealHeight(70), Width = Application.GetRealWidth(24), Height = Application.GetRealWidth(24), UnSelectedImagePath = "MusicIcon/filePause.png", SelectedImagePath = "MusicIcon/filePlay.png", Tag= list, }; addFlieRow.AddChidren(playIconBtn); playIconBtn.MouseUpEventHandler = (sender, e) => { ///查找当前播放音乐是否这个列表 if (playIconBtn.IsSelected) { if (list.ListName == A31MusicModel.Current.A31PlayStatus.Artist && A31MusicModel.Current.A31PlayStatus.status == "play") { SendMethod.Pause(A31MusicModel.Current); A31MusicModel.Current.A31PlayStatus.status = "pause"; } } else { if (list.MusicInfoList.Count == 0) { return; } if (list.ListName == A31MusicModel.Current.A31PlayStatus.Artist && A31MusicModel.Current.A31PlayStatus.status != "play") { SendMethod.Play(A31MusicModel.Current); A31MusicModel.Current.A31PlayStatus.status = "play"; } else { ///取随机数; var ra = new Random { }.Next(0, list.MusicInfoList.Count); ///查找当前的音乐; var songs = list.MusicInfoList[ra]; //点击按钮随机播放音乐 System.Threading.Tasks.Task.Run(() => { System.Threading.Thread.Sleep(50); Application.RunOnMainThread(() => { //移除界面 System.Threading.Tasks.Task.Run(() => { SendMethod.PushList(songs, list.ListName, list.MusicInfoList,A31MusicModel.Current, "我的列表"); }); }); }); } } }; //文件名控件 Button fileNameBtn = new Button { @@ -268,14 +204,14 @@ var playBtn = (Button)view.GetChildren(1);//直接FrameLayout父控件找到该控件Button var listIfon = playBtn.Tag as FileListInfo;//强制转换为FileListInfo类型; ///查找当前播放音乐是否这个列表 if (A31MusicModel.Current.A31PlayStatus.Artist == listIfon.ListName && A31MusicModel.Current.A31PlayStatus.status == "play") { playBtn.IsSelected = true; } else { playBtn.IsSelected = false; } //if (A31MusicModel.Current.A31PlayStatus.Artist == listIfon.ListName && A31MusicModel.Current.A31PlayStatus.status == "play") //{ // playBtn.IsSelected = true; //} //else //{ // playBtn.IsSelected = false; //} } } catch { } HDL_ON/UI/UI2/FuntionControlView/Music/A31MyListMusic.cs
@@ -47,14 +47,14 @@ public void MusicView(FileListInfo fileListInfo) { middViewLayout.RemoveAll(); UI2.FuntionControlView.Music.UpdateThread.playMusuc(middViewLayout,"我的列表", fileListInfo.ListName, fileListInfo.MusicInfoList, A31MusicModel.Current); // A31SongPlay.SongListView(middViewLayout,fileListInfo.ListName, fileListInfo.MusicInfoList); } /// <summary> /// 定时更新当前播放音乐 /// </summary> public void UpdateSelectedMusic() { UI2.FuntionControlView.Music.UpdateThread.updateThread(this, middViewLayout, A31MusicModel.Current); UpdateThread.updateCurrMusicThread(this, middViewLayout, A31MusicModel.Current); } HDL_ON/UI/UI2/FuntionControlView/Music/A31PlayMusicPage.cs
@@ -3,6 +3,7 @@ using com.hdl.on; using System.Collections.Generic; using System.Security; using HDL_ON.UI.UI2.FuntionControlView.Music; namespace HDL_ON.UI.Music { @@ -36,17 +37,19 @@ /// new布局界面 /// </summary> View.PlayView playView = new View.PlayView(); TopView topView; public void Show() { ///1秒定时更新状态 timerUpdateStatus(); #region ---界面布局--- this.BackgroundColor = MusicColor.ViewColor; var topView = new TopView(); topView = new TopView(); topView.setBtn.Visible = true; this.AddChidren(topView.TopFLayoutView()); topView.topNameBtn.Text = A31MusicModel.Current.Name; topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { RemoveFromParent(); @@ -74,105 +77,69 @@ playView.collectIconBtn.IsSelected = !playView.collectIconBtn.IsSelected; if (playView.collectIconBtn.IsSelected) { A31MusicModel.Current.collect = true; A31MusicModel.Current.functionMusic.collect = true; } else { A31MusicModel.Current.collect = false; A31MusicModel.Current.functionMusic.collect = false; } }; //快进滑动弹起事件; playView.diyArcSeekBar.OnStopTrackingTouchEvent+= (sender, e) => { int totalSecond = (int)(playView.diyArcSeekBar.Progress * 1.0f / 100 * 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()); SendMethod.Seek(time, A31MusicModel.Current); A31MusicModel.Current.A31PlayStatus.curpos = (DateTime.Parse(time) - DateTime.Parse("00:00:00")).TotalMilliseconds.ToString(); }; ///切换播放模式点击事件; playView.playOrderBtn.MouseUpEventHandler += (sender, e) => { string modeValueString = string.Empty; string msg = Language.StringByID(StringId.switchTo); switch (A31MusicModel.Current.A31PlayStatus.loop) switch (A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.mode)) { //0列表循环,1单曲循环,2随机播放; case "0": A31MusicModel.Current.A31PlayStatus.loop = "1"; //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 "1": A31MusicModel.Current.A31PlayStatus.loop = "2"; case ValueProperty.single_cycle: modeValueString =ValueProperty.random; playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/random.png"; msg += Language.StringByID(StringId.randomMode); break; case "2": A31MusicModel.Current.A31PlayStatus.loop = "0"; case ValueProperty.random: modeValueString = ValueProperty.list_cycle; playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/list.png"; msg += Language.StringByID(StringId.listMode); break; } A31MusicModel.Current.functionMusic.SetAttrState(KeyProperty.mode, modeValueString); new PublicAssmebly().TipMsgAutoClose(msg, false,1000); string url = "http://" + A31MusicModel.Current.IPAddress + "/httpapi.asp?command=setPlayerCmd:" + "loopmode:" + A31MusicModel.Current.A31PlayStatus.loop; SendMethod.SendCommand(url); Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add(KeyProperty.mode,modeValueString); SendMethod.mMethod.SendControlCommand(A31MusicModel.Current.functionMusic,dic); }; ///添加喜爱点击事件; playView.loveBtn.MouseUpEventHandler += (sender, e) => { var url = A31MusicModel.Current.A31PlayStatus.TrackURL; var album = A31MusicModel.Current.A31PlayStatus.Album; var artist = A31MusicModel.Current.A31PlayStatus.Artist; var song = A31MusicModel.Current.A31PlayStatus.Title; if (A31MusicModel.Current.A31PlayStatus.Source == "RADIO-NETWORK") var name = A31MusicModel.Current.functionMusic.GetAttribute("song_name").ToString(); var songTime = A31MusicModel.Current.functionMusic.GetAttribute("song_time").ToString(); playView.loveBtn.IsSelected = !playView.loveBtn.IsSelected; if (playView.loveBtn.IsSelected) { playView.loveBtn.IsSelected = !playView.loveBtn.IsSelected; if (playView.loveBtn.IsSelected) if (null == A31MusicModel.Current.LoveMusicInfoList.Find((musicInfo) => { if (null == A31MusicModel.Current.LoveRadioInfoList.Find((musicInfo) => { return url == musicInfo.URL; })) { A31MusicModel.Current.LoveRadioInfoList.Add(new MusicInfo { Title = song, URL = url, }); } } else return name == musicInfo.name; })) { A31MusicModel.Current.LoveRadioInfoList.RemoveAll((musicInfo) => { return url == musicInfo.URL; }); A31MusicModel.Current.LoveMusicInfoList.Add(new Songs { name = name, time = songTime }); } } else { playView.loveBtn.IsSelected = !playView.loveBtn.IsSelected; if (playView.loveBtn.IsSelected) A31MusicModel.Current.LoveMusicInfoList.RemoveAll((musicInfo) => { if (null == A31MusicModel.Current.LoveMusicInfoList.Find((musicInfo) => { return url == musicInfo.URL; })) { A31MusicModel.Current.LoveMusicInfoList.Add(new MusicInfo { Title = song, URL = url, Artist = artist, Album = album }); } } else { A31MusicModel.Current.LoveMusicInfoList.RemoveAll((musicInfo) => { //也要加歌手名判断 return musicInfo.URL == url; }); } //也要加歌手名判断 return musicInfo.name == name; }); } A31MusicModel.Save(); }; @@ -198,25 +165,18 @@ myListView.backIextBtn.MouseUpEventHandler += removeFromParentView; myListView.popFra.MouseUpEventHandler += removeFromParentView; #endregion loading.Start(); GetMusicList((listName) => { loading.Hide(); PlayListView(myListView.popFra, myListView.verticalScrolViewLayout, listName); UpdateSelectedMusic(myListView.popFra, myListView.verticalScrolViewLayout); }); //var listName = A31MusicModel.Current.functionMusic.GetAttribute("playlist_name").ToString(); //var musicList = A31MusicModel.Current.GetSongList(listName); //new A31SongPlay { }.SongListView(myListView.verticalScrolViewLayout, musicList, listName); PlayListView(myListView.popFra, myListView.verticalScrolViewLayout); UpdateSelectedMusic(myListView.popFra, myListView.verticalScrolViewLayout); }; ///音量图标点击事件 playView.volIconBtn.MouseUpEventHandler += (sender, e) => { if (A31MusicModel.Current.ServerClientType == 1 && A31MusicModel.Current.Slave.slave_list.Count != 0) { ///主播放器 var volumeView = new View.DialogView { }; volumeView.PlayerVolumeView(A31MusicModel.Current); volumeView.UpdateVolume(); } }; ///音量进度条点击事件 int startVolume =0;//之前的音量 @@ -227,8 +187,11 @@ if (startVolume != e) { startVolume = e; SendMethod.ControlVolume(e, A31MusicModel.Current); A31MusicModel.Current.A31PlayStatus.vol = e.ToString(); 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); } }; playView.volSeekBar.OnProgressChangedEvent += progressClick; @@ -237,7 +200,12 @@ playView.prevBtn.MouseDownEventHandler += (sender, e) => { playView.prevBtn.IsSelected = true; SendMethod.Previous(A31MusicModel.Current); 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); }; playView.prevBtn.MouseUpEventHandler += (sender, e) => { @@ -246,24 +214,30 @@ ///暂停/播放点击事件 playView.playBtn.MouseDownEventHandler += (sender, e) => { string status = string.Empty; if (playView.playBtn.IsSelected) { playView.playBtn.IsSelected = false; SendMethod.Pause(A31MusicModel.Current); A31MusicModel.Current.A31PlayStatus.status = "pause"; status = ValueProperty.off; } else { playView.playBtn.IsSelected = true; SendMethod.Play(A31MusicModel.Current); A31MusicModel.Current.A31PlayStatus.status = "play"; status = ValueProperty.on; } 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); }; ///下一曲点击事件 playView.nextBtn.MouseDownEventHandler += (sender, e) => { playView.nextBtn.IsSelected = true; SendMethod.Next(A31MusicModel.Current); 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); }; playView.nextBtn.MouseUpEventHandler += (sender, e) => { @@ -272,7 +246,7 @@ ///物理按键的点击事件 Volume.VolumeChange = (volume) => { if (Application.DeviceType == Device.Ios && A31MusicModel.Current.A31PlayStatus.Source == "BLUETOOTH") if (Application.DeviceType == Device.Ios && A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.source) == "bluetooth") { return; } @@ -281,8 +255,10 @@ if (startVolume != volume) { startVolume = volume; SendMethod.ControlVolume(volume, A31MusicModel.Current); A31MusicModel.Current.A31PlayStatus.vol = volume.ToString(); 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); } }; @@ -305,10 +281,9 @@ { try { //更新总时间 //总共有多少秒 int totalSecond = int.Parse(A31MusicModel.Current.A31PlayStatus.totlen) / 1000; int totalSecond = int.Parse(A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.song_time))/1000; //分钟 int totalMusicMinute = totalSecond / 60; //秒钟 @@ -317,54 +292,54 @@ 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.Name; switch (A31MusicModel.Current.A31PlayStatus.loop) topView.topNameBtn.Text = A31MusicModel.Current.functionMusic.name; string s = A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.mode); switch (A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.mode)) { case "0"://列表循环 case ValueProperty.list_cycle://列表循环 playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/list.png"; break; case "1"://单曲顺环 case ValueProperty.single_cycle://单曲循环 playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/single.png"; break; case "2"://随机播放 case ValueProperty.random://随机播放 playView.playOrderBtn.UnSelectedImagePath = "MusicIcon/random.png"; break; } if (A31MusicModel.Current.A31PlayStatus.Source == "RADIO-NETWORK") { var v = A31MusicModel.Current.LoveRadioInfoList.Find((like) => { return like.URL == A31MusicModel.Current.A31PlayStatus.TrackURL; }); if (v != null) { playView.loveBtn.IsSelected = true; } else { playView.loveBtn.IsSelected = false; } } else { var v = A31MusicModel.Current.LoveMusicInfoList.Find((like) => { return like.URL == A31MusicModel.Current.A31PlayStatus.TrackURL; }); if (v != null) { playView.loveBtn.IsSelected = true; } else { playView.loveBtn.IsSelected = false; } } playView.regionBtn.Text = A31MusicModel.Current.GetRoomListName(); if (A31MusicModel.Current.collect) //if (A31MusicModel.Current.A31PlayStatus.Source == "RADIO-NETWORK") //{ // var v = A31MusicModel.Current.LoveRadioInfoList.Find((like) => // { // return like.URL == A31MusicModel.Current.A31PlayStatus.TrackURL; // }); // if (v != null) // { // playView.loveBtn.IsSelected = true; // } // else // { // playView.loveBtn.IsSelected = false; // } //} //else //{ // var v = A31MusicModel.Current.LoveMusicInfoList.Find((like) => // { // return like.URL == A31MusicModel.Current.A31PlayStatus.TrackURL; // }); // if (v != null) // { // playView.loveBtn.IsSelected = true; // } // else // { // playView.loveBtn.IsSelected = false; // } //} playView.regionBtn.Text = A31MusicModel.Current.functionMusic.GetRoomListName(); if (A31MusicModel.Current.functionMusic.collect) { playView.collectIconBtn.IsSelected = true; } @@ -392,14 +367,15 @@ if (1000 < (DateTime.Now - A31MusicModel.ProgressDateTime).TotalMilliseconds) { //音量进度条; playView.volSeekBar.Progress = int.Parse(A31MusicModel.Current.A31PlayStatus.vol); playView.volSeekBar.Progress = int.Parse(A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.volume)); //显示当前音量值; playView.volValueBtn.Text = A31MusicModel.Current.A31PlayStatus.vol + "%"; playView.volValueBtn.Text = A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.volume) + "%"; } //更新播放器音量给系统音量 Volume.MusicVolume = playView.volSeekBar.Progress; //当前播放音乐时间 int playSecond = int.Parse(A31MusicModel.Current.A31PlayStatus.curpos) / 1000 + (int)(DateTime.Now - A31MusicModel.Current.LastDateTime).TotalSeconds; //当前播放音乐时间 //按道理不会为空,GetAttrState("playing_time")值可能为空,强制转换int.Parse()会出现异常,不过也做了异常处理了 int playSecond = int.Parse(A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.playing_time))+ (int)(DateTime.Now - A31MusicModel.Current.LastDateTime).TotalSeconds; int playMusicMinute = playSecond / 60; //秒钟 @@ -407,7 +383,7 @@ 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") if (A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.on_off) == ValueProperty.on) { playView.playBtn.IsSelected = true; //如果在播放,时间就不断变化 @@ -423,6 +399,7 @@ playView.diyArcSeekBar.Progress = (int)(playSecond * 100.0 / totalSecond);//+1 } } else { @@ -430,10 +407,10 @@ //停止播放 playView.startTimeBtn.Text =playTime; } playView.songNameTextView.Text = (A31MusicModel.Current.A31PlayStatus.Title == null ? "Unkown" : A31MusicModel.Current.A31PlayStatus.Title); playView.singerBtn.Text = (A31MusicModel.Current.A31PlayStatus.Artist == null ? "Unkown" : A31MusicModel.Current.A31PlayStatus.Artist.Trim()); 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) { @@ -469,7 +446,7 @@ playView.diyArcSeekBar.IsClickable = true; switch (A31MusicModel.Current.A31PlayStatus.Source) switch (A31MusicModel.Current.functionMusic.GetAttrState("source")) { case "QPLAY"://QQ音乐 @@ -539,91 +516,51 @@ /// 加载播放音乐列表View /// </summary> /// <param name="verticalScrolViewLayout"></param> void PlayListView(FrameLayout frameLayout, VerticalRefreshLayout verticalScrolViewLayout, string playListName) void PlayListView(FrameLayout frameLayout, VerticalRefreshLayout verticalScrolViewLayout) { verticalScrolViewLayout.RemoveAll(); UI2.FuntionControlView.Music.UpdateThread.playMusuc(verticalScrolViewLayout,"播放列表", playListName, A31MusicModel.Current.CurrentPlayMusicInfoList,A31MusicModel.Current,frameLayout); var listName = A31MusicModel.Current.functionMusic.GetAttrState(KeyProperty.playlist_name); var musicList = A31MusicModel.Current.GetSongList(listName); if (musicList.Count == 0) { System.Threading.Tasks.Task.Run(() => { try { A31MusicModel.Current.palyLists.Clear(); if (A31MusicModel.Current.palyLists.Count == 0) { SendMethod.mMethod.GetPalyList(A31MusicModel.Current.functionMusic); } } catch { } finally { Application.RunOnMainThread(() => { musicList = A31MusicModel.Current.GetSongList(listName); A31SongPlay.SongListView(verticalScrolViewLayout, musicList, listName, frameLayout); }); } }); } else { A31SongPlay.SongListView(verticalScrolViewLayout, musicList, listName, frameLayout); } } /// <summary> /// 定时更新当前播放音乐 /// </summary> void UpdateSelectedMusic(FrameLayout frameLayout, VerticalRefreshLayout middViewLayout) { UI2.FuntionControlView.Music.UpdateThread.updateThread(frameLayout, middViewLayout, A31MusicModel.Current); UpdateThread.updateCurrMusicThread(frameLayout, middViewLayout, A31MusicModel.Current); } /// <summary> /// 读取播放音乐列表 /// </summary> /// <param name="action"></param> void GetMusicList(Action<string> action) { System.Threading.Tasks.Task.Run(() => { string playListName = "List"; string sourceName = "SourceName"; try { if (A31MusicModel.Current.A31PlayStatus.Source == "STATION-NETWORK") { A31MusicModel.Current.CurrentPlayMusicInfoList = new List<MusicInfo>(); return; } if (A31MusicModel.Current.A31PlayStatus.Source == "AIRPLAY") { A31MusicModel.Current.CurrentPlayMusicInfoList = new List<MusicInfo>(); return; } var playString = SendMethod.GetCurrentPlayList(A31MusicModel.Current); A31MusicModel.Current.CurrentPlayMusicInfoList = new List<MusicInfo>(); 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<SendMethod.A31QQSong>(metadata); musicInfo.Album = qqSong.album; musicInfo.Title = qqSong.title; musicInfo.Artist = qqSong.creator; } else { metadata = metadata.Replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").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(() => { action(playListName); //loading.Hide(); //PlayListView(myListView.popFra, myListView.verticalScrolViewLayout, playListName); //UpdateSelectedMusic(myListView.popFra, myListView.verticalScrolViewLayout); }); } }); } } } HDL_ON/UI/UI2/FuntionControlView/Music/A31PlayStatus.cs
File was deleted HDL_ON/UI/UI2/FuntionControlView/Music/A31Radio.cs
File was deleted HDL_ON/UI/UI2/FuntionControlView/Music/A31RadioList.cs
File was deleted HDL_ON/UI/UI2/FuntionControlView/Music/A31SongPlay.cs
New file @@ -0,0 +1,149 @@ using System; using Shared; using HDL_ON.UI.Music; using System.Collections.Generic; namespace HDL_ON.UI.Music { public class A31SongPlay : FrameLayout { public A31SongPlay() { Tag = "Music"; } public void Show(List<Songs> musicList,string listName) { this.BackgroundColor = MusicColor.ViewColor; var topView = new TopView(); this.AddChidren(topView.TopFLayoutView()); topView.topNameBtn.TextID = StringId.localMusic; topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); }; var vv = new VerticalRefreshLayout { BackgroundColor = MusicColor.WhiteColor, Y = topView.fLayout.Bottom, Height = Application.GetRealHeight(H_W.H - H_W.T_Height), }; this.AddChidren(vv); vv.BeginHeaderRefreshingAction += () => { vv.EndHeaderRefreshing(); }; ///加载音乐列表 SongListView(vv, musicList, listName); } /// <summary> /// 加载音乐列表 /// </summary> /// <param name="vv">父控件</param> /// <param name="musicList">音乐列表</param> /// <param name="listName">列表名</param> public static void SongListView(VerticalRefreshLayout vv,List<Songs> musicList,string listName, 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(vv, songs); songView.songBtn.Text = songs.name; ///点击播放事件 songView.clickBtn.MouseUpEventHandler += (sender, e) => { System.Threading.Tasks.Task.Run(() => { System.Threading.Thread.Sleep(50); Application.RunOnMainThread(() => { //移除界面 A31MusicModel.Current.functionMusic.SetAttrState("song_name", songView.songBtn.Text); A31MusicModel.Current.functionMusic.SetAttrState("playlist_name", listName); //移除界面 if (frame != null) { frame.RemoveFromParent(); } MainPage.BasePageView.RemoveViewByTag("Music"); Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("song_name", songView.songBtn.Text); dic.Add("playlist_name", listName); SendMethod.mMethod.SendControlCommand(A31MusicModel.Current.functionMusic, dic); }); }); }; } } } public class UpdateThread { public UpdateThread() { } /// <summary> /// 定时更新当前播放音乐 /// </summary> /// <param name="frame">当前界面</param> /// <param name="middViewLayout">每一条音乐的主控件</param> /// <param name="a31MusicModel">点前播放器</param> public static void updateCurrMusicThread(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(); } } } HDL_ON/UI/UI2/FuntionControlView/Music/A31USBMusicList.cs
File was deleted HDL_ON/UI/UI2/FuntionControlView/Music/MusicMain.cs
@@ -3,19 +3,32 @@ using Shared; using Shared.IO; using System.Net; using HDL_ON.Entity; using HDL_ON.UI.UI2.FuntionControlView.Music; namespace HDL_ON.UI.Music { public class MusicMain : FrameLayout { private static MusicMain m_MusicMain = null; public static MusicMain mMusicMain { get { if (m_MusicMain == null) { m_MusicMain = new MusicMain(); } return m_MusicMain; } } /// <summary> /// MusicMain对象构造函数 /// </summary> public MusicMain() { Tag = "MusicMain"; //进来音乐列表界面先移除之前线程; A31MusicModel.RemoveListThread(); } /// <summary> /// 重写RemoveFromParent方法 @@ -24,7 +37,8 @@ { base.RemoveFromParent(); clearA31Threads(); A31MusicModel.ReadMusicStates();//进来没有音乐被收藏过,退出有音乐被收藏过 //进来没有音乐被收藏过,退出有音乐被收藏过 //A31MusicModel.ReadMusicStates(); } /// <summary> /// 创建线程列表 @@ -56,19 +70,22 @@ /// <summary> /// 显示加载界面 /// </summary> public static Loading loading = new Loading(); public static Loading loading = new Loading(); /// <summary> /// 定义全局对象 /// </summary> VerticalRefreshLayout verticalRefresh; /// <summary> /// 为了音乐刷新状态定义全局对象 /// </summary> MusicView musicView = new MusicView(); public void Show() { #region 界面布局 this.BackgroundColor = MusicColor.ViewColor; var topView = new TopView(); this.AddChidren(topView.TopFLayoutView()); topView.topNameBtn.TextID =StringId.a31Music; topView.topNameBtn.TextID = StringId.a31Music; topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { RemoveFromParent(); @@ -78,214 +95,120 @@ { Y = topView.fLayout.Bottom, Height = Application.GetRealHeight(H_W.H - H_W.T_Height), Name = "verticalRefresh", }; this.AddChidren(verticalRefresh); #endregion verticalRefresh.BeginHeaderRefreshingAction += () => { SeachMusic(false); verticalRefresh.EndHeaderRefreshing(); ////发送读取音乐播放器状态线程 SeachMusic(); }; this.AddChidren(loading); SeachMusic(); if (A31MusicModel.A31MusicModelList.Count == 0) { SeachMusic(true); } else { clearA31Threads(); //verticalRefresh.RemoveAll(); for (int i = 0; i < A31MusicModel.A31MusicModelList.Count; i++) { var a31player = A31MusicModel.A31MusicModelList[i]; ///这个状态是之前保存的,加载完成后要标记为不在线,后面再读取正确的状态 if (!a31player.IsCanShow) { continue; } if (A31MusicModel.A31MusicModelList.Count - 1 == i) { a31player.IsEnd = true; } else { a31player.IsEnd = false; } ///加载界面时默认不在线 ///这里标记是为了不读取不在线播放器状态 a31player.IsOnLine = false; MusicListView(a31player); } ///读取正确的信息,包括IP和端口及名称 SendMethod.Seach((obj) => { try { if (obj == null) { ///这里要读取主从关系 readServerOrClientMode(); A31MusicModel.Save(); return; } var a31MusicModel = A31MusicModel.A31MusicModelList.Find((music) => music.UniqueDeviceName == obj.UniqueDeviceName); if (a31MusicModel != null) { a31MusicModel.IPAddress = obj.IPAddress; a31MusicModel.Port = obj.Port; a31MusicModel.Name = obj.Name; a31MusicModel.IsCanShow = true; a31MusicModel.IsOnLine = true; } } catch (Exception e) { MainPage.Log(e.Message); } }); } } /// <summary> /// 刷新播放器列表 /// </summary> /// <param name="Yes">是否显示刷新图标</param> void SeachMusic(bool Yes = false) void SeachMusic() { for (int i = 0; i < A31MusicModel.A31MusicModelList.Count; i++) Application.RunOnMainThread(() => { var a31player = A31MusicModel.A31MusicModelList[i]; a31player.IsCanShow = false; a31player.IsOnLine = false; } if (Yes) { //为了第一次进来log一下; loading.Start(); } SendMethod.Seach((obj) => { if (obj == null) verticalRefresh.RemoveAll(); var musicListFunction = FunctionList.List.GetMusicList(); for (int i = 0; i < musicListFunction.Count; i++) { readServerOrClientMode(); A31MusicModel.Save(); if (!Yes) var function = musicListFunction[i]; var music = A31MusicModel.A31MusicModelList.Find((music) => (music.functionMusic.deviceId == function.deviceId && function.spk == "music.standard") || ( music.functionMusic.deviceId == function.deviceId && function.spk == "av.music") ); if (music == null) { ///等待跑完在关闭 verticalRefresh.EndHeaderRefreshing(); A31MusicModel.A31MusicModelList.Add(new A31MusicModel { functionMusic = function }); } else { music.functionMusic = function; } } for (int i = 0; i < A31MusicModel.A31MusicModelList.Count; i++) { var a31player = A31MusicModel.A31MusicModelList[i]; if (a31player.functionMusic.online == false) { //不在线不显示 continue; } Application.RunOnMainThread(() => { if (Yes) MusicListView(a31player); }); } ///进来读一次音乐播放器状态 for (int i = 0; i < A31MusicModel.A31MusicModelList.Count; i++) { var a31player = A31MusicModel.A31MusicModelList[i]; if (a31player.functionMusic.online == false) { //不在线不读取 continue; } //发送读取音乐播放器状态线程 System.Threading.Tasks.Task.Run(() => { try { //为了第一次进来log一下; loading.Hide(); SendMethod.mMethod.RefreshDeviceStatus(new List<string> { a31player.functionMusic.deviceId }); System.Threading.Thread.Sleep(500); } verticalRefresh.RemoveAll(); for (int i = 0; i < A31MusicModel.A31MusicModelList.Count; i++) { var a31player = A31MusicModel.A31MusicModelList[i]; //这个状态是之前保存的,加载完成后要标记为不在线,后面再读取正确的状态 if (!a31player.IsCanShow) { continue; } if (A31MusicModel.A31MusicModelList.Count - 1 == i) { a31player.IsEnd = true; } else { a31player.IsEnd = false; } MusicListView(a31player); } //A31MusicModel.ReadMusicStates(); catch { } }); return; } var a31MusicModel = A31MusicModel.A31MusicModelList.Find((music) => { return music.UniqueDeviceName == obj.UniqueDeviceName; }); if (a31MusicModel == null) { //不是我们支持的品牌不支持 if (obj.Name != null) { obj.sid = "030101123456780909020123AABB" + obj.UniqueDeviceName; A31MusicModel.A31MusicModelList.Add(obj); } } else { a31MusicModel.IPAddress = obj.IPAddress; a31MusicModel.Port = obj.Port; a31MusicModel.Name = obj.Name; a31MusicModel.IsCanShow = true; a31MusicModel.IsOnLine = true; } }); } /// <summary> /// 显示音乐列表的方法 /// </summary> void MusicListView(A31MusicModel a31player) void MusicListView(A31MusicModel player) { MusicView musicView = new MusicView(); musicView.View(verticalRefresh); musicView.singerBtn.Text = a31player.A31PlayStatus.Artist; musicView.songNameBtn.Text = a31player.A31PlayStatus.Title; musicView.musicNameBtn.Text = new View.DialogView { }.NamePlayer(a31player); if (a31player.IsEnd) { musicView.muiscFl.Height = Application.GetRealHeight(12 + 139 + 12); } musicView.ViewAddChidren(verticalRefresh); musicView.muiscFl.Tag = player.functionMusic;//多个音乐播放器更新状态要用到 musicView.singerBtn.Text = player.functionMusic.GetAttrState(KeyProperty.song_name); musicView.songNameBtn.Text = player.functionMusic.GetAttrState(KeyProperty.song_name); musicView.musicNameBtn.Text = player.functionMusic.name; ///收藏事件 musicView.collectIconBtn.MouseUpEventHandler += (sender, e) => { musicView.collectIconBtn.IsSelected = !musicView.collectIconBtn.IsSelected; if (a31player.ServerClientType == 1) if (musicView.collectIconBtn.IsSelected) { if (musicView.collectIconBtn.IsSelected) { a31player.MainPlayCollection = true; } else { a31player.MainPlayCollection = false; } player.functionMusic.collect = true; } else { if (musicView.collectIconBtn.IsSelected) { a31player.collect = true; } else { a31player.collect = false; } } A31MusicModel.Save(); }; EventHandler<MouseEventArgs> clickMergence = (sender, e) => { if (a31player.ServerClientType == 0) { new View.DialogView { }.PlayMergence(a31player); } else if (a31player.ServerClientType == 1) { new View.DialogView { }.DetachPlayMergence(a31player); player.functionMusic.collect = false; } }; musicView.mergeBjBtn.MouseUpEventHandler += clickMergence; musicView.mergeBtn.MouseUpEventHandler += clickMergence; musicView.mergeIconBtn.MouseUpEventHandler += clickMergence; ///进入音乐主页事件 EventHandler<MouseEventArgs> clickPlayView = (sender, e) => { A31MusicModel.Current = a31player;//当前播放器 A31MusicModel.Current = player; var a31PlayMusicPage = new A31PlayMusicPage(); MainPage.BasePageView.AddChidren(a31PlayMusicPage); a31PlayMusicPage.Show(); @@ -302,7 +225,10 @@ musicView.prevBtn.MouseDownEventHandler += (sender, e) => { musicView.prevBtn.IsSelected = true; SendMethod.Previous(a31player); player.functionMusic.SetAttrState(KeyProperty.song_step, ValueProperty.up); Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add(KeyProperty.song_step, ValueProperty.up); SendMethod.mMethod.SendControlCommand(player.functionMusic, dic); }; musicView.prevBtn.MouseUpEventHandler += (sender, e) => { @@ -311,46 +237,54 @@ ///暂停/播放点击事件 musicView.playBtn.MouseDownEventHandler += (sender, e) => { string status = ValueProperty.off; if (musicView.playBtn.IsSelected) { musicView.playBtn.IsSelected = false; SendMethod.Pause(a31player); a31player.A31PlayStatus.status = "pause"; status = ValueProperty.off; } else { musicView.playBtn.IsSelected = true; SendMethod.Play(a31player); a31player.A31PlayStatus.status = "play"; status = ValueProperty.on; } player.functionMusic.SetAttrState(KeyProperty.on_off, status); Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add(KeyProperty.on_off, status); SendMethod.mMethod.SendControlCommand(player.functionMusic, dic); }; ///下一曲点击事件 musicView.nextBtn.MouseDownEventHandler += (sender, e) => { musicView.nextBtn.IsSelected = true; SendMethod.Next(a31player); player.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(player.functionMusic, dic); }; musicView.nextBtn.MouseUpEventHandler += (sender, e) => { musicView.nextBtn.IsSelected = false; }; //更新状态线程 var musicThread = new System.Threading.Thread(() => { while (true) { System.Threading.Thread.Sleep(1000); if (!a31player.IsOnLine) if (!player.functionMusic.online) { ///不在线不读状态 continue; } SendMethod.ReadStatus(a31player); //SendMethod.ReadStatus(player); SendMethod.mMethod.GetDeviceStatus(ref player, new List<string> { player.functionMusic.deviceId }, player.functionMusic.sid); System.Threading.Thread.Sleep(1000); Application.RunOnMainThread(() => { musicView.singerBtn.Text = a31player.A31PlayStatus.Artist; musicView.songNameBtn.Text = a31player.A31PlayStatus.Title; musicView.musicNameBtn.Text = new View.DialogView { }.NamePlayer(a31player); if (a31player.A31PlayStatus.status == "play") musicView.singerBtn.Text = player.functionMusic.GetAttrState(KeyProperty.song_name); musicView.songNameBtn.Text = player.functionMusic.GetAttrState(KeyProperty.song_name); musicView.musicNameBtn.Text = player.functionMusic.name; if (player.functionMusic.GetAttrState(KeyProperty.on_off) == ValueProperty.on) { musicView.playBtn.IsSelected = true; } @@ -358,28 +292,15 @@ { musicView.playBtn.IsSelected = false; } musicView.regionBtn.Text = a31player.GetRoomListName(); if (a31player.ServerClientType == 1) musicView.regionBtn.Text = player.functionMusic.GetRoomListName(); if (player.functionMusic.collect) { if (a31player.MainPlayCollection) { musicView.collectIconBtn.IsSelected = true; } else { musicView.collectIconBtn.IsSelected = false; } musicView.collectIconBtn.IsSelected = true; } else { if (a31player.collect) { musicView.collectIconBtn.IsSelected = true; } else { musicView.collectIconBtn.IsSelected = false; } musicView.collectIconBtn.IsSelected = false; } }); } @@ -388,99 +309,121 @@ musicThread.Start(); threadLists.Add(musicThread); } /// <summary> /// 读取主从关系 ///指定刷新界面 /// </summary> void readServerOrClientMode() /// <param name="strView">判断字符</param> public void RefreshView(AlinkStatusData alinkStatusData) { try if (alinkStatusData == null || alinkStatusData.status.Count == 0) { for (int i = 0; i < A31MusicModel.A31MusicModelList.Count; i++) return; } Application.RunOnMainThread(() => { try { var a31player = A31MusicModel.A31MusicModelList[i]; if (!a31player.IsOnLine) for (int a =0; a < MainPage.BasePageView.ChildrenCount; a++) { continue; } try { a31player.ServerClientType = 0; var result = SendMethod.OpenWeb("http://" + a31player.IPAddress + "/httpapi.asp?command=multiroom:getSlaveList"); if (result == null && result == "Failed") var view = MainPage.BasePageView.GetChildren(a); if (view.GetType() == typeof(MusicMain)) { result = SendMethod.OpenWeb("http://" + a31player.IPAddress + "/httpapi.asp?command=multiroom:getSlaveList"); } if (result != null && result != "Failed") { a31player.Slave = Newtonsoft.Json.JsonConvert.DeserializeObject<Slaves>(result); } } catch (Exception e) { var d = e.Message; } } //分析主从关系 for (int i = 0; i < A31MusicModel.A31MusicModelList.Count; i++) { var a31player = A31MusicModel.A31MusicModelList[i]; if (!a31player.IsOnLine) { continue; } try { if (a31player.Slave != null && "0" != a31player.Slave.slaves) { a31player.ServerClientType = 1;//主的 string str = a31player.Name; for (int j = 0; j < a31player.Slave.slave_list.Count; j++) var musicMain = view as MusicMain; if (musicMain != null) { var slave = a31player.Slave.slave_list[j]; str = str + "+" + slave.name; var tempA31Player = A31MusicModel.A31MusicModelList.Find((obj) => slave.uuid.Replace("uuid:", "") == obj.UniqueDeviceName); if (tempA31Player == null) for (int b = 0; b < musicMain.ChildrenCount; b++) { A31MusicModel.A31MusicModelList.Add(new A31MusicModel var view1 = musicMain.GetChildren(b); if (view1.GetType() == typeof(VerticalRefreshLayout)) { sid = "030101123456780909020123AABB" + slave.uuid.Replace("uuid:", ""), ServerClientType = -1,//从的 IPAddress = slave.ip, MainPlayIP = a31player.IPAddress, UniqueDeviceName = slave.uuid.Replace("uuid:", ""), Name = slave.name, IsCanShow = false, IsOnLine = false,//true作用为了读取从播放器的音量 }); } //如果找到就更新为从的 else { tempA31Player.ServerClientType = -1;//从的 tempA31Player.IPAddress = slave.ip; tempA31Player.MainPlayIP = a31player.IPAddress; tempA31Player.Name = slave.name; tempA31Player.UniqueDeviceName = slave.uuid.Replace("uuid:", ""); tempA31Player.IsCanShow = false; tempA31Player.IsOnLine = false;//true作用为了读取从播放器的音量 var vv = view1 as VerticalRefreshLayout; if (vv != null && vv.Name == "verticalRefresh") { for (int c = 0; c < vv.ChildrenCount; c++) { var viewfl = vv.GetChildren(c); if (viewfl.GetType() == typeof(FrameLayout)) { var fl = viewfl as FrameLayout; if ((fl.Tag as Function).sid!= alinkStatusData.sid) { //不是当前音乐不会更新状态 continue; } if (fl != null && fl.Name == "parentfl") { for (int i = 0; i < fl.ChildrenCount; i++) { var viewfl1 = fl.GetChildren(i); if (viewfl1.GetType() == typeof(FrameLayout)) { var fl1 = viewfl1 as FrameLayout; if (fl1 != null && fl1.Name == "musicparentfl") { for (int j = 0; j < fl1.ChildrenCount; j++) { if (fl1.GetChildren(j).GetType() == typeof(Button)) { var btn = fl1.GetChildren(j) as Button; if (btn == null ||btn.Name==null) { continue; } switch (btn.Name) { case "song": { var s = alinkStatusData.status.Find((o) => o.key == KeyProperty.song_name); if (s != null) { btn.Text = s.value; } } break; case "playstatus": { var s = alinkStatusData.status.Find((o) => o.key == KeyProperty.on_off); if (s != null) { if (s.value == ValueProperty.on) { btn.IsSelected = true; } else { btn.IsSelected = false; } } } break; } } } } } } } } } } } } } a31player.MainPlayName = str; } } catch (Exception e) { var ss = e.Message; } } } catch { } catch { } }); } } } HDL_ON/UI/UI2/FuntionControlView/Music/MusicProperty.cs
New file @@ -0,0 +1,141 @@ using System; using HDL_ON.Entity; namespace HDL_ON.UI.UI2.FuntionControlView.Music { public class KeyProperty { private static KeyProperty sMusicPropertyKey = null; public static KeyProperty sMusicProperty { get { if (sMusicPropertyKey == null) { sMusicPropertyKey = new KeyProperty(); } return sMusicPropertyKey; } } #region ---属性---- /// <summary> /// 开关<on/off> /// </summary> public const string on_off = "on_off"; /// <summary> /// 音量<0-100> /// </summary> public const string volume = "volume"; /// <summary> /// 模式<single/single_cycle/order/list_cycle/random> /// </summary> public const string mode = "mode"; /// <summary> /// 音源<sdcard/audio_in/ftp/radio/bluetooth> /// </summary> public const string source = "source"; /// <summary> /// 列表名 /// </summary> public const string playlist_name = "playlist_name"; /// <summary> /// 歌曲名 /// </summary> public const string song_name = "song_name"; /// <summary> /// 切歌<up/down> /// </summary> public const string song_step = "song_step"; /// <summary> /// 当前歌曲总时间<0-9999(s)> /// </summary> public const string song_time = "song_time"; /// <summary> /// 当前歌曲播放时间<0-9999(s)> /// </summary> public const string playing_time = "playing_time"; #endregion /// <summary> /// 获取on_off值 /// </summary> /// <param name="function">当前音乐</param> /// <returns></returns> public string GetOnOffKeyValue(Function function) { if (function == null) { return ""; } return function.GetAttrState(on_off); } /// <summary> /// 设置on_off值 /// </summary> /// <param name="function">当前音乐</param> /// <returns></returns> public void SetOnOffKeyValue(Function function, string stateValue) { if (function == null) { return; } function.SetAttrState(on_off, stateValue); } } public class ValueProperty { #region ---属性值---- /// <summary> /// <up> /// </summary> public const string up = "up"; /// <summary> /// <down> /// </summary> public const string down = "down"; /// <summary> /// 开<on> /// </summary> public const string on = "on"; /// <summary> /// 关<off> /// </summary> public const string off = "off"; /// <summary> /// 单曲<single> /// </summary> public const string single = "single"; /// <summary> /// 单曲循环 /// </summary> public const string single_cycle = "single_cycle"; /// <summary> /// 循序循环 /// </summary> public const string order = "order"; /// <summary> /// 列表循环 /// </summary> public const string list_cycle = "list_cycle"; /// <summary> /// 随机播放 /// </summary> public const string random = "random"; #endregion } } HDL_ON/UI/UI2/FuntionControlView/Music/SendMethod.cs
@@ -4,883 +4,155 @@ using System.Net.Sockets; using System.Security; using System.Text; using HDL_ON.DAL.Server; using HDL_ON.Entity; using Shared; namespace HDL_ON.UI.Music { public class SendMethod { /// <summary> ///搜索A31音乐播放器 /// </summary> /// <param name="action"></param> /// <param name="time"></param> /// <param name="uid"></param> public static void Seach(Action<A31MusicModel> action, int time = 5 * 1000, string uid = "AllUniqueDeviceName") private static SendMethod sMethod=null; public static SendMethod mMethod { System.Threading.Tasks.Task.Run(() => get { System.Net.Sockets.UdpClient udpClient = null; int localPort = 65535; for (; 1024 < localPort; localPort--) if (sMethod == null) { try { udpClient = new System.Net.Sockets.UdpClient(localPort); break; } catch (Exception e) { System.Console.WriteLine(e.Message); } sMethod = new SendMethod(); } return sMethod; } System.Threading.Tasks.Task.Run(() => { var tempDateTime = DateTime.Now; while (udpClient != null) { try { if (time < (DateTime.Now - tempDateTime).TotalMilliseconds) { var tempBytes = System.Text.Encoding.UTF8.GetBytes("完成"); udpClient.Send(tempBytes, tempBytes.Length, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("127.0.0.1"), localPort)); } else { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("M-SEARCH * HTTP/1.1"); stringBuilder.AppendLine("St: ssdp:wiimudevice"); stringBuilder.AppendLine("Mx: 3"); stringBuilder.AppendLine("Host: 239.255.255.250:1900"); stringBuilder.AppendLine("Man: \"ssdp:discover\""); stringBuilder.AppendLine(); var tempBytes = System.Text.Encoding.ASCII.GetBytes(stringBuilder.ToString()); //请求获取A31服务器信息 udpClient.Send(tempBytes, tempBytes.Length, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.255.255.250"), 1900)); udpClient.Send(tempBytes, tempBytes.Length, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.255.255.250"), 1900)); //如果1000毫秒没有数据回复,就关闭当前Socket,不再等待接收数据 } System.Threading.Thread.Sleep(500); } catch (Exception e) { System.Console.WriteLine(e.Message); } } }); while (true) { try { //接收回来的数据 var remoteIpEndPoint = new System.Net.IPEndPoint(0, 0); //开始在这里等待接收数据, var receviceBytes = udpClient.Receive(ref remoteIpEndPoint); if (receviceBytes == null) { break; } if ("完成" == System.Text.Encoding.UTF8.GetString(receviceBytes)) { if (action != null) { //表示完成了 action(null); } try { udpClient.Close(); udpClient = null; } catch (Exception e) { System.Console.WriteLine(e.Message); } break; } var sr = new System.IO.StreamReader(new System.IO.MemoryStream(receviceBytes, 0, receviceBytes.Length)); string tempLine = null; string ipAddress = null; int port = 0; string uniqueDeviceName = null; //一行一行数据判断,找出需要的信息 while ((tempLine = sr.ReadLine()) != null) { //找出Ip地址相关的信息 //System.Console.WriteLine (tempLine); if (tempLine.StartsWith("LOCATION: http://")) { tempLine = tempLine.Replace("LOCATION: http://", "").Split('/')[0]; string[] ipAndPort = tempLine.Split(':'); ipAddress = ipAndPort[0]; port = int.Parse(ipAndPort[1]); } else if (tempLine.StartsWith("USN: uuid:")) { uniqueDeviceName = tempLine.Replace("USN: uuid:", "").Split(':')[0]; } } //关闭流 sr.Close(); if (action != null) { if ("AllUniqueDeviceName" == uid) { action(new A31MusicModel { IPAddress = ipAddress, Port = port, Name = GetDeviceName(ipAddress, port), UniqueDeviceName = uniqueDeviceName }); } else if (uid == uniqueDeviceName) { if (action != null) { //表示完成了 action(null); } try { udpClient.Close(); udpClient = null; } catch (Exception e) { System.Console.WriteLine(e.Message); } break; } } } catch (Exception e) { System.Console.WriteLine(e.Message); } } }); } /// <summary> /// 更新A31播放器的状态 /// 获取音乐列表 /// </summary> /// <param name="a31MusicModel"></param> public static void ReadStatus(A31MusicModel a31MusicModel) public List<Function> GetMusicList { get { return FunctionList.List.GetMusicList(); } } /// <summary> /// 发送控制命令 /// </summary> /// <param name="function">当前设备</param> /// <param name="dic">发送控制数据</param> public void SendControlCommand(Function function, Dictionary<string, string> dic) { new System.Threading.Thread(() => { DriverLayer.Control.Ins.SendWriteCommand(function, dic); }) { IsBackground = true }.Start(); } /// <summary> /// 获取设备最新的状态 /// </summary> /// <returns></returns> public void GetDeviceStatus(ref A31MusicModel a31Music, List<string> functionIds, string sid) { try { if (a31MusicModel.ServerClientType == 1) { var result = OpenWeb("http://" + a31MusicModel.IPAddress + "/httpapi.asp?command=multiroom:getSlaveList"); if (result != null && result != "Failed") { var slaves = Newtonsoft.Json.JsonConvert.DeserializeObject<Slaves>(result); if (slaves != null && slaves.slave_list != null && slaves.slave_list.Count != 0) { a31MusicModel.Slave = slaves; } } } WebClient webClient = new WebClient(); webClient.Headers.Add("Soapaction", "\"urn:schemas-upnp-org:service:AVTransport:1#GetInfoEx\""); webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); var recevieBytes = webClient.UploadData(new Uri("http://" + a31MusicModel.IPAddress + ":" + a31MusicModel.Port + "/upnp/control/rendertransport1"), "POST", System.Text.Encoding.UTF8.GetBytes("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:GetInfoEx xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:GetInfoEx></s:Body></s:Envelope>")); a31MusicModel.LastDateTime = DateTime.Now;//记录数据反馈的时间(因为有时间网络差数据不回复,导致当前播放音乐时间显示不正确) var se = System.Security.SecurityElement.FromString(System.Text.Encoding.UTF8.GetString(recevieBytes)).SearchForChildByTag("s:Body").SearchForChildByTag("u:GetInfoExResponse"); if ("PLAYING" == se.SearchForTextOfTag("CurrentTransportState")) { a31MusicModel.A31PlayStatus.status = "play"; } else { a31MusicModel.A31PlayStatus.status = "stop"; } a31MusicModel.A31PlayStatus.totlen = (DateTime.Parse(se.SearchForTextOfTag("TrackDuration")) - DateTime.Parse("00:00:00")).TotalMilliseconds.ToString(); var trackMetaData = se.SearchForTextOfTag("TrackMetaData"); if (string.IsNullOrEmpty(trackMetaData)) // RefreshDeviceStatus(functionIds); a31Music.LastDateTime = DateTime.Now; ///从缓存里面查找音乐播放器对象<缓存数据收到推送过来的状态会更新缓存数据> var allLocalFuntion = FunctionList.List.GetDeviceFunctionList(); var localFunction = allLocalFuntion.Find((obj) => obj.sid == sid); if (localFunction == null) { return; } if (A31MusicModel.IsJson(trackMetaData)) { var a31QQSong = Newtonsoft.Json.JsonConvert.DeserializeObject<A31QQSong>(trackMetaData); a31MusicModel.A31PlayStatus.Title = a31QQSong.title; a31MusicModel.A31PlayStatus.Album = a31QQSong.album; a31MusicModel.A31PlayStatus.Artist = a31QQSong.creator; } else { var metadata = trackMetaData.Replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").Replace("&", "&amp;"); var item = SecurityElement.FromString(metadata).SearchForChildByTag("item"); a31MusicModel.A31PlayStatus.Title = item.SearchForTextOfTag("dc:title"); a31MusicModel.A31PlayStatus.Artist = item.SearchForTextOfTag("upnp:artist"); a31MusicModel.A31PlayStatus.Album = item.SearchForTextOfTag("upnp:album"); } a31MusicModel.A31PlayStatus.curpos = (DateTime.Parse(se.SearchForTextOfTag("RelTime")) - DateTime.Parse("00:00:00")).TotalMilliseconds.ToString(); a31MusicModel.A31PlayStatus.vol = se.SearchForTextOfTag("CurrentVolume"); a31MusicModel.A31PlayStatus.loop = se.SearchForTextOfTag("LoopMode"); a31MusicModel.A31PlayStatus.Source = se.SearchForTextOfTag("PlayMedium"); a31MusicModel.A31PlayStatus.playSource = se.SearchForTextOfTag("TrackSource"); a31MusicModel.A31PlayStatus.TrackURL = se.SearchForTextOfTag("TrackURI").Replace("&", "&amp;"); ///更新的数据 a31Music.functionMusic = localFunction; } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { #region 更新其他界面音乐状态 Application.RunOnMainThread(() => { a31MusicModel.trait_on_off.curValue = a31MusicModel.A31PlayStatus.status == "play" ? "on" : "off"; //Console.WriteLine($"music : {a31MusicModel.sid} : {a31MusicModel.on_off}"); HomePage.UpdataFunctionStates(a31MusicModel); foreach (var e in A31MusicModel.A31MusicModelList) { RoomPage.UpdataStates(a31MusicModel); } }); #endregion } catch { } } public static string OpenWeb(string url) { try { var webClient = new WebClient(); return webClient.DownloadString(url); } catch (Exception e) { System.Console.WriteLine(e.Message); return null; } } /// <summary> /// 获取A31的名称 /// 刷新设备状态 /// </summary> /// <param name="ip"></param> /// <param name="port"></param> /// <returns></returns> static string GetDeviceName(string ip, int port) public void RefreshDeviceStatus(List<string> functionIds) { string deviceName = null; System.IO.StreamReader sr = null; WebClient webClient = new WebClient(); try { var receviceBytes = webClient.DownloadData(new Uri("http://" + ip + ":" + port + "/description.xml")); sr = new System.IO.StreamReader(new System.IO.MemoryStream(receviceBytes), Encoding.UTF8); string line = null; string deviceType = null; while ((line = sr.ReadLine()) != null) Dictionary<string, object> d = new Dictionary<string, object>(); d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id); d.Add("deviceIds", functionIds); var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_RefreshDeviceStatus); if (responsePackNew.Code != "0" || responsePackNew.Data == null || responsePackNew.Data.ToString() == "") { //System.Console.WriteLine (line); if (line.StartsWith("<friendlyName>")) { deviceName = line.Replace("<friendlyName>", "").Replace("</friendlyName>", ""); } else if (line.StartsWith("<manufacturer>")) { deviceType = line.Replace("<manufacturer>", "").Replace("</manufacturer>", ""); } return; } switch (deviceType) { case "iEAST": case "Linkplay Technology Inc.": break; //不是A31的音乐数据 default: deviceName = null; break; } } catch (Exception e) { System.Console.WriteLine(e.Message); } finally { if (sr != null) { sr.Close(); } } return deviceName; } /// <summary> /// 切换播放器模式,修改音乐名称,切换蓝牙,线路输入 /// </summary> /// <param name="coutn"></param> public static void SendCommand(string url) { System.Threading.Tasks.Task.Run(() => { WebClient webClient = new WebClient(); try { byte[] recevieBytes1 = webClient.DownloadData(new Uri(url)); } catch (Exception ex) { //this.IPAddress = ex.Message; } }); } /// <summary> /// 播放 /// </summary> public static void Play(A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { StringBuilder sb = new 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:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">"); sb.AppendLine("<InstanceID>0</InstanceID>"); sb.AppendLine("<Speed>1</Speed>"); sb.AppendLine("</u:Play>"); sb.AppendLine("</s:Body>"); sb.AppendLine("</s:Envelope>"); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Play\""); webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } catch { } }); } /// <summary> /// 暂停 /// </summary> public static void Pause(A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { StringBuilder sb = new 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:Pause xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">"); sb.AppendLine("<InstanceID>0</InstanceID>"); sb.AppendLine("</u:Pause>"); sb.AppendLine("</s:Body>"); sb.AppendLine("</s:Envelope>"); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Pause\""); webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } catch { } }); } /// <summary> /// 下一曲 /// </summary> public static void Next(A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { StringBuilder sb = new 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:Next xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">"); sb.AppendLine("<InstanceID>0</InstanceID>"); sb.AppendLine("</u:Next>"); sb.AppendLine("</s:Body>"); sb.AppendLine("</s:Envelope>"); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Next\""); webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } catch { } }); } /// <summary> /// 上一曲 /// </summary> public static void Previous(A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { StringBuilder sb = new 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:Previous xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">"); sb.AppendLine("<InstanceID>0</InstanceID>"); sb.AppendLine("</u:Previous>"); sb.AppendLine("</s:Body>"); sb.AppendLine("</s:Envelope>"); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Previous\""); webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } catch { } }); } /// <summary> /// 快进 /// </summary> public static void Seek(string seekvolume, A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { StringBuilder sb = new 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:Seek xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">"); sb.AppendLine("<InstanceID>0</InstanceID>"); sb.AppendLine("<Unit>REL_TIME</Unit>"); sb.AppendLine("<Target>" + seekvolume + "</Target>"); sb.AppendLine("</u:Seek>"); sb.AppendLine("</s:Body>"); sb.AppendLine("</s:Envelope>"); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Seek\""); webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } catch { } }); } /// <summary> /// 调节音量 /// </summary> /// <param name="volume">Volume.</param> public static void ControlVolume(int volume, A31MusicModel a31player) { System.Threading.Tasks.Task.Run(() => { A31MusicModel.ProgressDateTime = DateTime.Now; try { if (a31player.ServerClientType == -1) { new System.Net.WebClient().DownloadData(new Uri("http://" + a31player.MainPlayIP + "/httpapi.asp?command=multiroom:SlaveVolume:" + a31player.IPAddress + ":" + volume)); } else if (a31player.ServerClientType == 1) { new System.Net.WebClient().DownloadData(new Uri("http://" + a31player.IPAddress + "/httpapi.asp?command=setPlayerCmd:slave_vol:" + volume)); } else { var sb = new 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:SetVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\">"); sb.AppendLine("<InstanceID>0</InstanceID>"); sb.AppendLine("<Channel>Master</Channel>"); sb.AppendLine("<DesiredVolume>" + volume + "</DesiredVolume>"); sb.AppendLine("</u:SetVolume>"); sb.AppendLine("</s:Body>"); sb.AppendLine("</s:Envelope>"); var webClient = new System.Net.WebClient(); webClient.Headers.Add("SOAPACTION", "\"urn:schemas-upnp-org:service:RenderingControl:1#SetVolume\""); webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/rendercontrol1"), "POST", Encoding.UTF8.GetBytes(sb.ToString())); } } catch { } }); } /// <summary> /// 获取USb的列表 /// </summary> public static List<MusicInfo> GetUsbList(A31MusicModel a31player) { var musicInfoList = new List<MusicInfo>(); musicInfoList.Clear(); var usbString = GetUSBPlayList(a31player); if (usbString == null) { return musicInfoList; } var se = System.Security.SecurityElement.FromString(usbString); if (se == null) { return musicInfoList; } while (se.Children != null) { se = se.Children[0] as System.Security.SecurityElement; } 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").Replace("&", "&"); var item = SecurityElement.FromString(metadata).SearchForChildByTag("item"); musicInfo.Title = item.SearchForTextOfTag("dc:title").Replace("&", "&amp;"); musicInfo.Artist = item.SearchForTextOfTag("upnp:artist").Replace("&", "&amp;"); musicInfo.Album = item.SearchForTextOfTag("upnp:album").Replace("&", "&amp;"); musicInfo.Duration = item.SearchForTextOfTag("res"); musicInfo.AlbumId = item.SearchForTextOfTag("song:albumid").Replace("&", "&amp;"); musicInfoList.Add(musicInfo); } return musicInfoList; } /// <summary> ///请求USB列表命令 /// </summary> public static string GetUSBPlayList(A31MusicModel a31player) { StringBuilder getPlayList = new StringBuilder(); getPlayList.AppendLine("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"); getPlayList.AppendLine("<s:Body>"); getPlayList.AppendLine("<u:BrowseQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">"); getPlayList.AppendLine("<QueueName>USBDiskQueue</QueueName>"); getPlayList.AppendLine("</u:BrowseQueue>"); getPlayList.AppendLine("</s:Body>"); getPlayList.AppendLine("</s:Envelope>"); WebClient webClient = new WebClient(); 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://" + a31player.IPAddress + ":" + a31player.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; } /// <summary> /// 读取电台组列表 /// </summary> /// <returns>读取到的电台组列表信息,读取不到反馈为null</returns> public static string ReadRadioList(string url) { WebClient webClient = new WebClient(); webClient.Proxy = null; webClient.Headers.Add("Content-type", "plain/text; charset=UTF-8"); if (Language.CurrentLanguage == "Chinese") { webClient.Headers.Add("Accept-Language", "zh-cn"); } else { webClient.Headers.Add("Accept-Language", "en-us"); } try { byte[] recevieBytes = webClient.DownloadData(new Uri(url)); return System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); } catch (Exception e) { return null; } } /// <summary> /// 获取当前播放的列表 /// </summary> public static string GetCurrentPlayList(A31MusicModel a31player) { System.Text.StringBuilder getPlayList = new System.Text.StringBuilder(); getPlayList.AppendLine("<?xml version=\"1.0\"encoding=\"utf-8\"?>"); getPlayList.AppendLine("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"); getPlayList.AppendLine("<s:Body>"); getPlayList.AppendLine("<u:BrowseQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">"); getPlayList.AppendLine("<QueueName>CurrentQueue</QueueName>"); getPlayList.AppendLine("</u:BrowseQueue>"); getPlayList.AppendLine("</s:Body>"); getPlayList.AppendLine("</s:Envelope>"); System.Net.WebClient webClient = new System.Net.WebClient(); 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://" + a31player.IPAddress + ":" + a31player.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; } /// <summary> /// 播放USB音乐命令 /// </summary> /// <param name="listName">列表名称</param> /// <param name="number">播放索引</param> public static void ListMusicPlay(string listName, object number, A31MusicModel a31player) { System.Text.StringBuilder playstrings = new System.Text.StringBuilder(); playstrings.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>"); playstrings.AppendLine("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"); playstrings.AppendLine("<s:Body>"); playstrings.AppendLine("<u:PlayQueueWithIndex xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">"); playstrings.AppendLine("<QueueName>" + listName + "</QueueName>"); playstrings.AppendLine("<Index>" + number + "</Index>"); playstrings.AppendLine("</u:PlayQueueWithIndex>"); playstrings.AppendLine("</s:Body>"); playstrings.AppendLine("</s:Envelope>"); 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[] recevieBytes = webClient.UploadData(new Uri("http://" + a31player.IPAddress + ":" + a31player.Port + "/upnp/control/PlayQueue1"), "POST", Encoding.UTF8.GetBytes(playstrings.ToString())); var s = System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); } catch { } } /// <summary> /// 设备名称修改 /// </summary> public string EditDeviceName(string deviceId, string deviceName) { Dictionary<string, object> d = new Dictionary<string, object>(); d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id); d.Add("deviceId", deviceId); d.Add("name", deviceName); var requestJson = HttpUtil.GetSignRequestJson(d); return HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_EditDeviceName, requestJson).Code; } /// <summary> /// 推送播放命令 /// 获取音乐列表 /// </summary> /// <param name="musicInfo">播放音乐</param> /// <param name="listName">列表名称</param> /// <param name="musicList">推送列表(默认推50首)</param> public static void PushList(MusicInfo musicInfo, string listName, List<MusicInfo> musicList, A31MusicModel a31player,string musicSource) /// <param name="music"></param> /// <returns></returns> public void GetPalyList(Function music) { //最大发送的条数 int maxCount = 50; //找出当前点击音乐的索引 int statIndex = musicList.FindIndex((obj) => { return obj == musicInfo; }); //点击后面还有多少条音乐 int count = musicList.Count - statIndex; int endIndex = 0; if (maxCount < count) { //如果后面的音乐大于最大数,设置后面数据的最大索引 endIndex = statIndex + maxCount - 1; } else { //如果后面数据不多,就用总数减去最大条数,得到开始索引 statIndex = musicList.Count - maxCount - 1; endIndex = musicList.Count - 1; } //如果开始索引小于0,那就设置为第一条音乐 if (statIndex < 0) { statIndex = 0; } StringBuilder sb = new StringBuilder(); sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); 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:CreateQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">"); sb.AppendLine("<QueueContext><?xml version=\"1.0\"?>"); sb.AppendLine("<PlayList>"); sb.AppendLine("<ListName>DLNA" + listName + "</ListName>"); sb.AppendLine("<ListInfo>"); sb.AppendLine("<Radio>0</Radio>");// sb.AppendLine("<SourceName>UPnPServer</SourceName>");// sb.AppendLine("<MarkSearch>0</MarkSearch>"); sb.AppendLine("<TrackNumber>" + (endIndex - statIndex + 1) + "</TrackNumber>"); sb.AppendLine("<Quality>0</Quality>"); sb.AppendLine("<UpdateTime>5367</UpdateTime>"); sb.AppendLine("<LastPlayIndex>2</LastPlayIndex>"); sb.AppendLine("<SwitchPageMode>0</SwitchPageMode>"); sb.AppendLine("<CurrentPage>0</CurrentPage>"); sb.AppendLine("<TotalPages>0</TotalPages>"); sb.AppendLine("</ListInfo>"); sb.AppendLine("<Tracks>"); int number = 1; for (int i = statIndex, Tracknumber = 1; i <= endIndex; i++, Tracknumber++) { var tempMusicInfo = musicList[i]; if (musicInfo == tempMusicInfo) { number = Tracknumber; } if (tempMusicInfo.SourceType == "Local") { tempMusicInfo.URL = "http://" + new Shared.Net.NetWiFi().IpAddress + ":" + com.hdl.on.Server.Port + "/" + tempMusicInfo.ID; } sb.AppendLine("<Track" + Tracknumber + ">"); sb.AppendLine("<URL>" + tempMusicInfo.URL + "</URL>"); sb.AppendLine("<Metadata>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;"); sb.AppendLine("&lt;DIDL-Lite xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; xmlns:upnp=&quot;urn:schemas-upnp-org:metadata-1-0/upnp/&quot; xmlns:song=&quot;www.wiimu.com/song/&quot; xmlns=&quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&quot;&gt;"); sb.AppendLine("&lt;upnp:class&gt;object.item.audioItem.musicTrack&lt;/upnp:class&gt;"); sb.AppendLine("&lt;item id=&quot;0&quot;&gt;"); sb.AppendLine("&lt;song:subid&gt;&lt;/song:subid&gt;"); sb.AppendLine("&lt;song:description&gt;unknown&lt;/song:description&gt;"); sb.AppendLine("&lt;song:skiplimit&gt;6&lt;/song:skiplimit&gt;"); sb.AppendLine("&lt;song:id&gt;" + tempMusicInfo.ID + "&lt;/song:id&gt;"); sb.AppendLine("&lt;song:like&gt;0&lt;/song:like&gt;"); sb.AppendLine("&lt;song:singerid&gt;0&lt;/song:singerid&gt;"); sb.AppendLine("&lt;song:albumid&gt;" + tempMusicInfo.AlbumId + "&lt;/song:albumid&gt;"); sb.AppendLine("&lt;res protocolInfo=&quot;http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;&quot; duration=&quot;" + "0:0:0.0" + "&quot;&gt;" + tempMusicInfo.URL + "&lt;/res&gt;"); sb.AppendLine("&lt;dc:title&gt;" + tempMusicInfo.Title + "&lt;/dc:title&gt;"); sb.AppendLine("&lt;dc:creator&gt;DJ Sanny J&lt;/dc:creator&gt;"); if (musicSource== "我的列表") { sb.AppendLine("&lt;upnp:artist&gt;" + listName + "&lt;/upnp:artist&gt;"); } else { sb.AppendLine("&lt;upnp:artist&gt;" + tempMusicInfo.Artist + "&lt;/upnp:artist&gt;"); } sb.AppendLine("&lt;upnp:album&gt;" + tempMusicInfo.Album + "&lt;/upnp:album&gt;"); sb.AppendLine("&lt;upnp:albumArtURI&gt;unknown&lt;/upnp:albumArtURI&gt;"); sb.AppendLine("&lt;/item&gt;"); sb.AppendLine("&lt;/DIDL-Lite&gt;"); sb.AppendLine("</Metadata>"); sb.AppendLine("<Id>" + tempMusicInfo.ID + "</Id>"); sb.AppendLine("<Source>STATION-NETWORK</Source>");//UPnPServer sb.AppendLine("<Key>" + tempMusicInfo.URL + "</Key>"); sb.AppendLine("</Track" + Tracknumber + ">"); } sb.AppendLine("</Tracks>"); sb.AppendLine("</PlayList>"); sb.AppendLine("</QueueContext>"); sb.AppendLine("</u:CreateQueue>"); sb.AppendLine("</s:Body>"); sb.AppendLine("</s:Envelope>"); SendMusicLists(a31player.IPAddress, a31player.Port, "CreateQueue", sb.ToString()); StringBuilder playString = new StringBuilder(); playString.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); playString.AppendLine("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"); playString.AppendLine("<s:Body>"); playString.AppendLine("<u:PlayQueueWithIndex xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">"); playString.AppendLine("<QueueName>DLNA" + listName + "</QueueName>"); playString.AppendLine("<Index>" + number + "</Index>"); playString.AppendLine("</u:PlayQueueWithIndex>"); playString.AppendLine("</s:Body>"); playString.AppendLine("</s:Envelope>"); Play(a31player.IPAddress, a31player.Port, playString.ToString()); } static void SendMusicLists(string ip, int port, string soapAction, string listInfo) { System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#" + soapAction + "\""); webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { byte[] recevieBytes = webClient.UploadData(new Uri("http://" + ip + ":" + port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(listInfo)); var s = System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); } catch(Exception e) { var d = e.Message; } } static void Play(string ip, int port, string info) { 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[] recevieBytes = webClient.UploadData(new Uri("http://" + ip + ":" + port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(info)); var s = System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); Dictionary<string, object> d = new Dictionary<string, object>(); d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id); d.Add("deviceIds", new List<string> { music.deviceId }); var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_PlayerList); if (responsePackNew.Code != "0"||responsePackNew.Data == null ||responsePackNew.Data.ToString() == "") { return; } //数据返序列化为Function对象 var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data); var palyLists = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PalyListInfo>>(str); if (palyLists == null) { palyLists =new List<PalyListInfo>(); } if (palyLists.Count > 0) { ///默认拿第一个列表 A31MusicModel.Current.palyLists = palyLists[0].playlist; } } catch { } } static System.Threading.Thread thread; /// <summary> /// 修改蓝牙名称 ///请求服务器(与住宅有关:例如;homeId) /// </summary> /// <param name="message"></param> public static void ModifyBluetoothName(string message) /// <returns></returns> public ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 5) { if (thread != null) { thread.Abort(); } thread = new System.Threading.Thread(() => { var tcpClient = new TcpClient() { ReceiveTimeout = 1000 }; try { //进行连接 tcpClient.Connect(new IPEndPoint(IPAddress.Parse(A31MusicModel.Current.IPAddress), 8899)); var buffter = Encoding.UTF8.GetBytes(message); var sendByes = new byte[20 + buffter.Length]; sendByes[0] = 0x18; sendByes[1] = 0x96; sendByes[2] = 0x18; sendByes[3] = 0x20; var requestJson = HttpUtil.GetSignRequestJson(o); return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout); sendByes[4] = (byte)((buffter.Length & 0x000000FF) >> 0); sendByes[5] = (byte)((buffter.Length & 0x0000FF00) >> 8); sendByes[6] = (byte)((buffter.Length & 0x00FF0000) >> 16); sendByes[7] = (byte)((buffter.Length & 0xFF000000) >> 24); var checkSum = getCheckSum(buffter); sendByes[8] = (byte)((checkSum & 0x000000FF) >> 0); sendByes[9] = (byte)((checkSum & 0x0000FF00) >> 8); sendByes[10] = (byte)((checkSum & 0x00FF0000) >> 16); sendByes[11] = (byte)((checkSum & 0xFF000000) >> 24); sendByes[16] = 0x08; Array.Copy(buffter, 0, sendByes, 20, buffter.Length); tcpClient.GetStream().Write(sendByes, 0, sendByes.Length); tcpClient.GetStream().Flush(); thread = null; } catch { } finally { tcpClient.Close(); } }); thread.Start(); } static uint getCheckSum(byte[] buffer) { uint check_sum = 0; for (int i = 0; i < buffer.Length; i++) { check_sum += buffer[i]; } return check_sum; } public class A31QQSong { public string title = string.Empty; public string album = string.Empty; public string creator = string.Empty; } } } HDL_ON/UI/UI2/FuntionControlView/Music/UpdateThread.cs
File was deleted HDL_ON/UI/UI2/FuntionControlView/Music/View/DialogView.cs
@@ -9,7 +9,7 @@ ///弹窗文件夹列表界面 /// </summary> /// <param name="musicInfo"></param> public void FieListView(MusicInfo musicInfo) public void FieListView(Songs musicInfo) { #region //主控件 @@ -114,7 +114,7 @@ FileView(dialog, verticalScrolViewLayout, musicInfo); } void FileView(Dialog dialog, VerticalScrolViewLayout verticalScrolViewLayout, MusicInfo musicInfo) void FileView(Dialog dialog, VerticalScrolViewLayout verticalScrolViewLayout, Songs musicInfo) { verticalScrolViewLayout.RemoveAll(); for (int i = 0; i < A31MusicModel.Current.FileLists.Count; i++) @@ -207,7 +207,7 @@ EventHandler<MouseEventArgs> click = (sender, e) => { if (null == list.MusicInfoList.Find((music) => music.URL == musicInfo.URL)) if (null == list.MusicInfoList.Find((music) => music.name == musicInfo.name)) { list.MusicInfoList.Add(musicInfo); A31MusicModel.Save(); @@ -222,1241 +222,6 @@ } } /// <summary> /// 选中组合的播放器的界面 /// </summary> public void PlayMergence(A31MusicModel a31MusicModel) { #region //主控件 Dialog dialog = new Dialog() { BackgroundColor = MusicColor.PopupBackgroundColor, }; dialog.Show(); //父控件 FrameLayout frame = new FrameLayout { }; dialog.AddChidren(frame); frame.MouseUpEventHandler += (sen, e) => { dialog.Close(); }; //白色快父控件 FrameLayout dialogFra = new FrameLayout() { X = Application.GetRealWidth(16), Y = Application.GetRealHeight(397), Width = Application.GetRealWidth(344), Height = Application.GetRealHeight(250), BackgroundColor = MusicColor.WhiteColor, Radius = (uint)Application.GetRealHeight(12), }; frame.AddChidren(dialogFra); //显示头部信息父控件 FrameLayout topFra = new FrameLayout() { Width = Application.GetRealWidth(344), Height = Application.GetRealHeight(50), }; dialogFra.AddChidren(topFra); //取消控件 Button cancelnBtn = new Button { X = Application.GetRealWidth(20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(20), TextID = StringId.cancelMusic, TextAlignment = TextAlignment.CenterLeft, TextColor = MusicColor.MusicNoTxetColor, TextSize = TextSize.Text14, }; topFra.AddChidren(cancelnBtn); cancelnBtn.MouseUpEventHandler += (sen, e) => { dialog.Close(); }; //标题控件 Button txetBtn = new Button { X = cancelnBtn.Right + Application.GetRealWidth(20), Y = Application.GetRealHeight(14), Width = Application.GetRealWidth(152), Height = Application.GetRealHeight(22), TextColor = MusicColor.TextColor, TextSize = TextSize.Text16, TextAlignment = TextAlignment.Center, TextID = StringId.selectedMergence, IsBold = true, }; topFra.AddChidren(txetBtn); //确认控件 Button confirmBtn = new Button { X = Application.GetRealWidth(344 - 60 - 20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(20), TextID = StringId.confirmMusic, TextAlignment = TextAlignment.CenterRight, TextColor = MusicColor.SelectedColor, TextSize = TextSize.Text14, }; topFra.AddChidren(confirmBtn); VerticalScrolViewLayout verticalScrolViewLayout = new VerticalScrolViewLayout { Y = Application.GetRealHeight(50), Height = dialogFra.Height - Application.GetRealHeight(50), Width = Application.GetRealWidth(344), }; dialogFra.AddChidren(verticalScrolViewLayout); var playList1 = new List<A31MusicModel>(); for (int i = 0; i < A31MusicModel.A31MusicModelList.Count; i++) { var player = A31MusicModel.A31MusicModelList[i]; if (!player.IsOnLine) { //不在线不显示; continue; } RowLayout PlayRow = new RowLayout { Height = Application.GetRealHeight(50), LineColor = MusicColor.WhiteColor, SubViewWidth = Application.GetRealWidth(80),//改变编辑控件宽度多少; }; verticalScrolViewLayout.AddChidren(PlayRow); //播放器名称控件 Button PlayNameBtn = new Button { X = Application.GetRealWidth(20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(150), Height = Application.GetRealHeight(20), TextColor = MusicColor.TextColor, TextSize = TextSize.Text14, TextAlignment = TextAlignment.CenterLeft, Text = NamePlayer(player), }; PlayRow.AddChidren(PlayNameBtn); //选中图标控件 Button selectedIconBtn = new Button { X = Application.GetRealWidth(303), Y = Application.GetRealHeight(11), Width = Application.GetRealWidth(28), Height = Application.GetRealWidth(28), UnSelectedImagePath = "MusicIcon/noSelectedIcon.png", SelectedImagePath = "MusicIcon/selectedIcon.png", }; PlayRow.AddChidren(selectedIconBtn); ///加大几点范围 Button clickBtn = new Button { Height = Application.GetRealHeight(50), }; PlayRow.AddChidren(clickBtn); if (a31MusicModel.UniqueDeviceName == player.UniqueDeviceName) { clickBtn.IsSelected = selectedIconBtn.IsSelected = true; playList1.Add(a31MusicModel); } clickBtn.MouseUpEventHandler += (sender, e) => { clickBtn.IsSelected = !clickBtn.IsSelected; selectedIconBtn.IsSelected = clickBtn.IsSelected; var musicPlayer = playList1.Find((c) => c.UniqueDeviceName == player.UniqueDeviceName); if (selectedIconBtn.IsSelected) { if (musicPlayer == null) { playList1.Add(player); } } else { if (musicPlayer != null) { playList1.Remove(player); } } }; //线 Button lineBtn = new Button { Y = PlayRow.Height - 1, X = Application.GetRealWidth(20), Width = Application.GetRealWidth(304), Height = 1, BackgroundColor = MusicColor.LineColor, }; PlayRow.AddChidren(lineBtn); } #endregion confirmBtn.MouseUpEventHandler += (sender, e) => { if (playList1.Count <= 1) { new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.selectAtLeastTwoPlayers), false); return; } int number = 0; foreach (var musin in playList1) { if (musin.ServerClientType == 1) { number++; } } if (number >= 2) { new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.cannotSelectTwoOrMoreMainPlayersToCombine), false); //如果都是主播放我就不能组合; return; } ///查询是否已经存在主播放; var host_Music_If = playList1.Find((c) => c.ServerClientType == 1); if (host_Music_If == null) { var playList2 = new List<A31MusicModel>(); for (int i = 0; i < playList1.Count; i++) { var musics = playList1[i]; if (musics.A31PlayStatus.status == "play") { playList2.Add(musics); } } if (playList2.Count == 0) { SelectedPlayerView(dialog, playList1, playList1); } else if (playList2.Count == 1) { //只有一个播放器在播放,默认为主播发器; dialog.Close(); var player = playList2[0]; MergeThreading(player, playList1); } else { SelectedPlayerView(dialog, playList1, playList2); } } else { dialog.Close(); MergeThreading(host_Music_If, playList1); } }; } /// <summary> /// 选中某个音乐为主播放器的界面 /// </summary> /// <param name="musicList1">显示将要组合的播放器列表</param> /// /// <param name="musicList2">显示在播放音乐播放器列表</param> void SelectedPlayerView(Dialog dialogF, List<A31MusicModel> musicList1, List<A31MusicModel> musicList2) { #region //主控件 Dialog dialog = new Dialog() { //BackgroundColor = Color.PopupBackgroundColor, }; dialog.Show(); //父控件 FrameLayout frame = new FrameLayout { }; dialog.AddChidren(frame); frame.MouseUpEventHandler += (sen, e) => { dialog.Close(); }; //白色快父控件 FrameLayout dialogFra = new FrameLayout() { X = Application.GetRealWidth(16), Y = Application.GetRealHeight(397), Width = Application.GetRealWidth(344), Height = Application.GetRealHeight(250), BackgroundColor = MusicColor.WhiteColor, Radius = (uint)Application.GetRealHeight(12), }; frame.AddChidren(dialogFra); //显示头部信息父控件 FrameLayout topFra = new FrameLayout() { Width = Application.GetRealWidth(344), Height = Application.GetRealHeight(50), }; dialogFra.AddChidren(topFra); //取消控件 Button cancelnBtn = new Button { X = Application.GetRealWidth(20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(20), TextID = StringId.cancelMusic, TextAlignment = TextAlignment.CenterLeft, TextColor = MusicColor.MusicNoTxetColor, TextSize = TextSize.Text14, }; topFra.AddChidren(cancelnBtn); cancelnBtn.MouseUpEventHandler += (sen, e) => { dialog.Close(); }; //标题控件 Button txetBtn = new Button { X = cancelnBtn.Right + Application.GetRealWidth(20), Y = Application.GetRealHeight(14), Width = Application.GetRealWidth(152), Height = Application.GetRealHeight(22), TextColor = MusicColor.TextColor, TextSize = TextSize.Text16, TextAlignment = TextAlignment.Center, TextID = StringId.readyPlay, IsBold = true, }; topFra.AddChidren(txetBtn); //确认控件 Button confirmBtn = new Button { X = Application.GetRealWidth(344 - 60 - 20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(20), TextID = StringId.confirmMusic, TextAlignment = TextAlignment.CenterRight, TextColor = MusicColor.SelectedColor, TextSize = TextSize.Text14, }; topFra.AddChidren(confirmBtn); VerticalScrolViewLayout verticalScrolViewLayout = new VerticalScrolViewLayout { Y = Application.GetRealHeight(50), Height = dialogFra.Height - Application.GetRealHeight(50), Width = Application.GetRealWidth(344), }; dialogFra.AddChidren(verticalScrolViewLayout); //记录选中状态 Button selectedBtn = new Button() { Name = "No" }; for (int i = 0; i < musicList2.Count; i++) { var player = musicList2[i]; RowLayout addFlieRow = new RowLayout { Height = Application.GetRealHeight(50), LineColor = MusicColor.WhiteColor, }; verticalScrolViewLayout.AddChidren(addFlieRow); if (player.A31PlayStatus.status == "play") { Button songNameBtn = new Button { X = Application.GetRealWidth(20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(150), Height = Application.GetRealHeight(20), TextColor = MusicColor.TextColor, TextSize = TextSize.Text14, TextAlignment = TextAlignment.CenterLeft, Text = player.A31PlayStatus.Title, }; addFlieRow.AddChidren(songNameBtn); var wText = songNameBtn.GetTextWidth();//获取文本宽度 if (wText >Application.GetRealWidth(220)) { songNameBtn.Width = Application.GetRealWidth(220); } else { songNameBtn.Width = wText + Application.GetRealWidth(15); } //歌手控件 Button singerBtn = new Button { X = songNameBtn.Right, Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(220)- wText, Height = Application.GetRealHeight(20), TextColor = MusicColor.MusicNoTxetColor, TextSize = TextSize.Text12, TextAlignment = TextAlignment.CenterLeft, Text = "-" + player.A31PlayStatus.Artist.Trim(), }; addFlieRow.AddChidren(singerBtn); } else { //播放器名称控件 Button PlayNameBtn = new Button { X = Application.GetRealWidth(20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(150), Height = Application.GetRealHeight(20), TextColor = MusicColor.TextColor, TextSize = TextSize.Text14, TextAlignment = TextAlignment.CenterLeft, Text = NamePlayer(player), }; addFlieRow.AddChidren(PlayNameBtn); } //选中图标控件 Button selectedIconBtn = new Button { X = Application.GetRealWidth(303), Y = Application.GetRealHeight(11), Width = Application.GetRealWidth(28), Height = Application.GetRealWidth(28), UnSelectedImagePath = "MusicIcon/noSelectedIcon.png", SelectedImagePath = "MusicIcon/selectedIcon.png", Tag = player, }; addFlieRow.AddChidren(selectedIconBtn); ///加大几点范围 Button clickBtn = new Button { Height = Application.GetRealHeight(50), }; addFlieRow.AddChidren(clickBtn); clickBtn.MouseUpEventHandler += (sender, e) => { selectedBtn.IsSelected = false; selectedBtn = selectedIconBtn; selectedBtn.Name = "Yes"; selectedBtn.IsSelected = true; }; //线 Button lineBtn = new Button { Y = addFlieRow.Height - 1, X = Application.GetRealWidth(20), Width = Application.GetRealWidth(304), Height = 1, BackgroundColor = MusicColor.LineColor, }; addFlieRow.AddChidren(lineBtn); } #endregion confirmBtn.MouseUpEventHandler += (sender, e) => { if (selectedBtn.Name.ToString() == "No") { new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.noSelectedPlay), false); return; } dialogF.Close(); dialog.Close(); var serverMusic = selectedBtn.Tag as A31MusicModel; MergeThreading(serverMusic, musicList1); }; } /// <summary> /// 选中解除组合的播放器的界面 /// </summary> public void DetachPlayMergence(A31MusicModel a31player) { #region //主控件 Dialog dialog = new Dialog() { BackgroundColor = MusicColor.PopupBackgroundColor, }; dialog.Show(); //父控件 FrameLayout frame = new FrameLayout { }; dialog.AddChidren(frame); frame.MouseUpEventHandler += (sen, e) => { dialog.Close(); }; //白色快父控件 FrameLayout dialogFra = new FrameLayout() { X = Application.GetRealWidth(16), Y = Application.GetRealHeight(397), Width = Application.GetRealWidth(344), Height = Application.GetRealHeight(250), BackgroundColor = MusicColor.WhiteColor, Radius = (uint)Application.GetRealHeight(12), }; frame.AddChidren(dialogFra); //显示头部信息父控件 FrameLayout topFra = new FrameLayout() { Width = Application.GetRealWidth(344), Height = Application.GetRealHeight(50), }; dialogFra.AddChidren(topFra); //取消控件 Button cancelnBtn = new Button { X = Application.GetRealWidth(20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(20), TextID = StringId.cancelMusic, TextAlignment = TextAlignment.CenterLeft, TextColor = MusicColor.MusicNoTxetColor, TextSize = TextSize.Text14, }; topFra.AddChidren(cancelnBtn); cancelnBtn.MouseUpEventHandler += (sen, e) => { dialog.Close(); }; //标题控件 Button txetBtn = new Button { X = cancelnBtn.Right + Application.GetRealWidth(20), Y = Application.GetRealHeight(14), Width = Application.GetRealWidth(152), Height = Application.GetRealHeight(22), TextColor = MusicColor.TextColor, TextSize = TextSize.Text16, TextAlignment = TextAlignment.Center, TextID = StringId.checkTheReleasePlayer, //Text = "选中解除播放器", IsBold = true, }; topFra.AddChidren(txetBtn); //确认控件 Button confirmBtn = new Button { X = Application.GetRealWidth(344 - 60 - 20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(20), TextID = StringId.confirmMusic, TextAlignment = TextAlignment.CenterRight, TextColor = MusicColor.SelectedColor, TextSize = TextSize.Text14, }; topFra.AddChidren(confirmBtn); VerticalScrolViewLayout verticalScrolViewLayout = new VerticalScrolViewLayout { Y = Application.GetRealHeight(50), Height = dialogFra.Height - Application.GetRealHeight(50), Width = Application.GetRealWidth(344), }; dialogFra.AddChidren(verticalScrolViewLayout); var playList1 = new List<A31MusicModel>(); playList1.Add(a31player); for (int i = 0; i < a31player.Slave.slave_list.Count; i++) { var slave = a31player.Slave.slave_list[i]; var music_If = A31MusicModel.A31MusicModelList.Find((c) => c.UniqueDeviceName == slave.uuid.Replace("uuid:", "")); if (music_If != null) { playList1.Add(music_If); } } var playList2 = new List<A31MusicModel>(); for (int i = 0; i < playList1.Count; i++) { var player = playList1[i]; RowLayout PlayRow = new RowLayout { Height = Application.GetRealHeight(50), LineColor = MusicColor.WhiteColor, SubViewWidth = Application.GetRealWidth(80),//改变编辑控件宽度多少; }; verticalScrolViewLayout.AddChidren(PlayRow); //播放器名称控件 Button PlayNameBtn = new Button { X = Application.GetRealWidth(20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(150), Height = Application.GetRealHeight(20), TextColor = MusicColor.TextColor, TextSize = TextSize.Text14, TextAlignment = TextAlignment.CenterLeft, Text = NamePlayer(player), }; PlayRow.AddChidren(PlayNameBtn); //选中图标控件 Button selectedIconBtn = new Button { X = Application.GetRealWidth(303), Y = Application.GetRealHeight(11), Width = Application.GetRealWidth(28), Height = Application.GetRealWidth(28), UnSelectedImagePath = "MusicIcon/noSelectedIcon.png", SelectedImagePath = "MusicIcon/selectedIcon.png", }; PlayRow.AddChidren(selectedIconBtn); ///加大几点范围 Button clickBtn = new Button { Height = Application.GetRealHeight(50), Tag = player.UniqueDeviceName, }; PlayRow.AddChidren(clickBtn); clickBtn.MouseUpEventHandler += (sender, e) => { clickBtn.IsSelected = !clickBtn.IsSelected; selectedIconBtn.IsSelected = clickBtn.IsSelected; var uuid = playList2.Find((obj) => obj.UniqueDeviceName == clickBtn.Tag.ToString()); if (selectedIconBtn.IsSelected) { if (uuid == null) { playList2.Add(player); } } else { if (uuid != null) { playList2.Remove(player); } } }; //线 Button lineBtn = new Button { Y = PlayRow.Height - 1, X = Application.GetRealWidth(20), Width = Application.GetRealWidth(304), Height = 1, BackgroundColor = MusicColor.LineColor, }; PlayRow.AddChidren(lineBtn); } #endregion confirmBtn.MouseUpEventHandler += (sender, e) => { if (playList1.Count == 0) { new PublicAssmebly().TipMsgAutoClose(Language.StringByID(StringId.noCheckTheReleasePlayer), false); return; } dialog.Close(); RemoveThreading(a31player, playList2); }; } /// <summary> /// 发送组合命令逻辑处理的方法 /// </summary> /// <param name="serverMusic">主播放器</param> /// <param name="musicList1"></param> void MergeThreading(A31MusicModel serverMusic, List<A31MusicModel> musicList1) { A31MusicModel mainModel = null; bool mainModelCollection = false; MusicMain.loading.Start(Language.StringByID(StringId.inConfiguration)); bool _if = false; System.Threading.Tasks.Task.Run(() => { try { var statusEx = SendMethod.OpenWeb("http://" + serverMusic.IPAddress + "/httpapi.asp?command=getStatusEx"); if (statusEx == null) { statusEx = SendMethod.OpenWeb("http://" + serverMusic.IPAddress + "/httpapi.asp?command=getStatusEx"); } if (statusEx == null) { return; } var serverIfon = Newtonsoft.Json.JsonConvert.DeserializeObject<A31Wifi>(statusEx); if (serverIfon == null) { return; } string ssid = ""; foreach (var b in serverIfon.ssid) { ssid += System.Convert.ToString(b, 16).ToUpper().Length < 2 ? "0" + System.Convert.ToString(b, 16).ToUpper() : System.Convert.ToString(b, 16).ToUpper(); } System.Threading.Thread.Sleep(1000); for (int i = 0; i < musicList1.Count; i++) { var clientMusic = musicList1[i]; if (clientMusic.UniqueDeviceName == serverMusic.UniqueDeviceName) { //过滤掉主播放器; continue; } var dd = SendMethod.OpenWeb("http://" + clientMusic.IPAddress + "/httpapi.asp?command=ConnectMasterAp:ssid=" + ssid + ":ch=" + serverIfon.WifiChannel + ":auth=OPEN:encry=NONE:pwd=:chext=0:JoinGroupMaster:eth" + serverIfon.eth2 + ":wifi" + serverIfon.ra0 + ":uuid" + serverIfon.uuid); if (null == SendMethod.OpenWeb("http://" + clientMusic.IPAddress + "/httpapi.asp?command=ConnectMasterAp:ssid=" + ssid + ":ch=" + serverIfon.WifiChannel + ":auth=OPEN:encry=NONE:pwd=:chext=0:JoinGroupMaster:eth" + serverIfon.eth2 + ":wifi" + serverIfon.ra0 + ":uuid" + serverIfon.uuid)) { if (null == SendMethod.OpenWeb("http://" + clientMusic.IPAddress + "/httpapi.asp?command=ConnectMasterAp:ssid=" + ssid + ":ch=" + serverIfon.WifiChannel + ":auth=OPEN:encry=NONE:pwd=:chext=0:JoinGroupMaster:eth" + serverIfon.eth2 + ":wifi" + serverIfon.ra0 + ":uuid" + serverIfon.uuid)) { } } System.Threading.Thread.Sleep(1000);//等待1秒再发数据 } DateTime dateTime = DateTime.Now; while ((DateTime.Now - dateTime).TotalMilliseconds < 15 * 1000) { System.Threading.Thread.Sleep(1000); try { var result = SendMethod.OpenWeb("http://" + serverMusic.IPAddress + "/httpapi.asp?command=multiroom:getSlaveList"); if (result != null && result != "Failed") { var tmepSlaves = Newtonsoft.Json.JsonConvert.DeserializeObject<Slaves>(result); if (tmepSlaves != null && tmepSlaves.slave_list != null && tmepSlaves.slave_list.Count != 0) { string str = serverMusic.Name; for (int j = 0; j < A31MusicModel.A31MusicModelList.Count; j++) { var music = A31MusicModel.A31MusicModelList[j]; if(music.collect && !mainModelCollection) { mainModelCollection = true; } if (music.UniqueDeviceName == serverMusic.UniqueDeviceName) { music.ServerClientType = 1; mainModel = music; music.Slave = tmepSlaves; //过滤掉主播放器; continue; } var slave_Ifon = tmepSlaves.slave_list.Find((obj) => obj.uuid.Replace("uuid:", "") == music.UniqueDeviceName); if (null != slave_Ifon) { str = str + "+" + slave_Ifon.name; //已经添加成功 music.ServerClientType = -1; music.IsCanShow = false; music.IsOnLine = false; music.IPAddress = slave_Ifon.ip; music.MainPlayIP = serverMusic.IPAddress; _if = true; } } serverMusic.MainPlayName = str; foreach(var music in A31MusicModel.A31MusicModelList) { if(music.ServerClientType == 1) { music.MainPlayCollection = mainModelCollection; } } A31MusicModel.Save(); break; } } } catch { } } } catch { } finally { Application.RunOnMainThread(() => { MusicMain.loading.Hide(); ///可以提示配置失败; if (_if) { //配置成功才可以刷新界面 MainPage.BasePageView.RemoveViewByTag("MusicMain"); var musicMain = new MusicMain(); MainPage.BasePageView.AddChidren(musicMain); musicMain.Show(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; } }); } }); } /// <summary> /// 解除组合命令逻辑处理的方法 /// </summary> /// <param name="a31player">主播放器</param> /// <param name="playList1"></param> void RemoveThreading(A31MusicModel a31player, List<A31MusicModel> playList1) { MusicMain.loading.Start(Language.StringByID(StringId.lifting)); var slaveList = new List<Slave>(); slaveList.AddRange(a31player.Slave.slave_list); // bool host_If = false; //表示是否显示解除的播放 bool _if = false; System.Threading.Tasks.Task.Run(() => { try { var play_If = playList1.Find((obj) => obj.UniqueDeviceName == a31player.UniqueDeviceName); if (play_If == null) { //子音箱与主音箱断开的命令 for (int i = 0; i < playList1.Count; i++) { var clientMusic = playList1[i]; if (null == SendMethod.OpenWeb("http://" + a31player.IPAddress + "/httpapi.asp?command=multiroom:SlaveKickout:" + clientMusic.IPAddress)) { if (null == SendMethod.OpenWeb("http://" + a31player.IPAddress + "/httpapi.asp?command=multiroom:SlaveKickout:" + clientMusic.IPAddress)) { } } ///每解除一个播放器需要等待3秒 System.Threading.Thread.Sleep(3000);//等待3秒再发数据 } } else { //解散组的命令 if (null == SendMethod.OpenWeb("http://" + a31player.IPAddress + "/httpapi.asp?command=multiroom:Ungroup")) { if (null == SendMethod.OpenWeb("http://" + a31player.IPAddress + "/httpapi.asp?command=multiroom:Ungroup")) { } } } DateTime dateTime = DateTime.Now; while ((DateTime.Now - dateTime).TotalMilliseconds < 12 * 1000) { System.Threading.Thread.Sleep(1000); try { var result = SendMethod.OpenWeb("http://" + a31player.IPAddress + "/httpapi.asp?command=multiroom:getSlaveList"); if (result != null && result != "Failed") { var tmepSlaves = Newtonsoft.Json.JsonConvert.DeserializeObject<Slaves>(result); if (tmepSlaves != null) { if (tmepSlaves.slave_list.Count == 0) { var host_music = A31MusicModel.A31MusicModelList.Find((c) => c.UniqueDeviceName == a31player.UniqueDeviceName); if (host_music != null) { host_music.ServerClientType = 0;//解除主从关系 host_music.MainPlayName = ""; } for (int a = 0; a < slaveList.Count; a++) { var uuid = slaveList[a].uuid.Replace("uuid:", ""); var music = A31MusicModel.A31MusicModelList.Find((c) => c.UniqueDeviceName == uuid); if (music != null) { music.ServerClientType = 0;//解除主从关系 music.IsCanShow = true;//允许显示 music.IsOnLine = false;//先不允许读取 } } } else { for (int b = 0; b < tmepSlaves.slave_list.Count; b++) { var uuid = tmepSlaves.slave_list[b].uuid.Replace("uuid:", ""); var music = A31MusicModel.A31MusicModelList.Find((c) => c.UniqueDeviceName == uuid); if (music != null) { music.ServerClientType = 0;//解除主从关系 music.IsCanShow = true;//允许显示 music.IsOnLine = false;//先不允许读取 } } } var host_a31player = A31MusicModel.A31MusicModelList.Find((c) => c.UniqueDeviceName == a31player.UniqueDeviceName); string str = host_a31player.Name; for (int b = 0; b < tmepSlaves.slave_list.Count; b++) { str = str + "+" + tmepSlaves.slave_list[b].name; } host_a31player.MainPlayName = str;///改变主播放器的显示名称 _if = true;//解除成功 A31MusicModel.Save(); break; } } } catch { } } } catch { } finally { Application.RunOnMainThread(() => { MusicMain.loading.Hide(); ///可以提示解除失败; if (_if) { //解除成功才可以刷新界面 MainPage.BasePageView.RemoveViewByTag("MusicMain"); var musicMain = new MusicMain(); MainPage.BasePageView.AddChidren(musicMain); musicMain.Show(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; } }); } }); } /// <summary> /// 播放器名称 /// </summary> public string NamePlayer(A31MusicModel a31player) { if (a31player.ServerClientType == 1) { return a31player.MainPlayName; } else { return a31player.Name; } } List<A31MusicModel> volumePlayList = new List<A31MusicModel>(); A31MusicModel currVolumePlay = null;//当前的播放器 int startVolume = 0;//之前的音量 int endVolume = 0;//现在的音量 string if_volume ="";//标记是调节总音量还是单个播放器音量; /// <summary> /// 播放器音量的界面 /// </summary> /// <param name="a31player">主播放器</param> public void PlayerVolumeView(A31MusicModel a31player) { volumePlayList.Clear(); for (int i = 0; i < a31player.Slave.slave_list.Count; i++) { var slave = a31player.Slave.slave_list[i]; var music_If = A31MusicModel.A31MusicModelList.Find((c) => c.UniqueDeviceName == slave.uuid.Replace("uuid:", "")); if (music_If != null) { music_If.ServerClientType = -1; music_If.A31PlayStatus.vol = slave.volume; volumePlayList.Add(music_If); } } volumePlayList.Add(a31player); #region //主控件 Dialog volumedialog = new Dialog(); volumedialog.Show(); //父控件 FrameLayout frame = new FrameLayout { }; volumedialog.AddChidren(frame); //白色快父控件 FrameLayout dialogFra = new FrameLayout() { X = Application.GetRealWidth(16), Y = Application.GetRealHeight(397-20), Width = Application.GetRealWidth(344), Height = Application.GetRealHeight(250+20), BackgroundColor = MusicColor.WhiteColor, Radius = (uint)Application.GetRealHeight(12), }; frame.AddChidren(dialogFra); #region 确认 取消 //显示头部信息父控件 FrameLayout topFra = new FrameLayout() { Width = Application.GetRealWidth(344), Height = Application.GetRealHeight(58), }; dialogFra.AddChidren(topFra); //取消控件 Button cancelnBtn = new Button { X = Application.GetRealWidth(20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(20), TextID = StringId.cancelMusic, TextAlignment = TextAlignment.CenterLeft, TextColor = MusicColor.MusicNoTxetColor, TextSize = TextSize.Text14, }; topFra.AddChidren(cancelnBtn); //标题控件 Button txetBtn = new Button { X = cancelnBtn.Right + Application.GetRealWidth(20), Y = Application.GetRealHeight(14), Width = Application.GetRealWidth(152), Height = Application.GetRealHeight(22), TextColor = MusicColor.TextColor, TextSize = TextSize.Text16, TextAlignment = TextAlignment.Center, TextID = StringId.volumeAdjustment, IsBold = true, }; topFra.AddChidren(txetBtn); //确认控件 Button confirmBtn = new Button { X = Application.GetRealWidth(344 - 60 - 20), Y = Application.GetRealHeight(15), Width = Application.GetRealWidth(60), Height = Application.GetRealHeight(20), TextID = StringId.confirmMusic, TextAlignment = TextAlignment.CenterRight, TextColor = MusicColor.SelectedColor, TextSize = TextSize.Text14, }; topFra.AddChidren(confirmBtn); EventHandler<MouseEventArgs> eventHandler= (sen,e) => { volumedialog.Close(); if (updateVolumeThread != null) { try { if (updateVolumeThread.IsAlive) { updateVolumeThread.Abort(); } } catch { } } }; cancelnBtn.MouseUpEventHandler += eventHandler; confirmBtn.MouseUpEventHandler += eventHandler; frame.MouseUpEventHandler += eventHandler; #endregion #region 总音量的View FrameLayout totalVolumeFra = new FrameLayout { Height = Application.GetRealHeight(64), Y = Application.GetRealHeight(58), }; dialogFra.AddChidren(totalVolumeFra); Button totalvolumeTextBtn = new Button { X = Application.GetRealWidth(28), Y = Application.GetRealHeight(8), Width = Application.GetRealWidth(200), Height = Application.GetRealHeight(14), TextColor = MusicColor.MusicNoTxetColor, TextSize = TextSize.Text10, TextAlignment = TextAlignment.CenterLeft, Text = Language.StringByID(StringId.totalVolume), }; totalVolumeFra.AddChidren(totalvolumeTextBtn); DiyImageSeekBar totalVolSeekBar = new DiyImageSeekBar { Y = Application.GetRealHeight(12), X = Application.GetRealWidth(28), Width = Application.GetRealWidth(240), Height = Application.GetRealHeight(54),//进度条父控件背景高度 IsProgressTextShow = false,//显示百分比 IsClickable = true,//进度条是否滑动 ProgressBarColor = MusicColor.SelectedColor,//选中进度条颜色 ThumbImagePath = "MusicIcon/progressIcon.png",//进度条按钮图标 ThumbImageHeight = Application.GetRealWidth(54),//进度条按钮图标的高度(默认正方形:宽和高一样) SeekBarViewHeight = Application.GetRealWidth(8),//进度条的高度 Progress = int.Parse(a31player.A31PlayStatus.vol), SeekBarPadding = Application.GetRealWidth(20), //ProgressChangeDelayTime= }; totalVolumeFra.AddChidren(totalVolSeekBar); Button totalVolumeValueBtn = new Button { X = Application.GetRealWidth(289), Y = Application.GetRealHeight(31), Width = Application.GetRealWidth(26 + 15), Height = Application.GetRealHeight(17), TextColor = MusicColor.MusicNoTxetColor, TextSize = TextSize.Text12, TextAlignment = TextAlignment.CenterLeft, Text = totalVolSeekBar.Progress.ToString() + "%", }; totalVolumeFra.AddChidren(totalVolumeValueBtn); #endregion VerticalScrolViewLayout volumeViewLayout = new VerticalScrolViewLayout { Y =Application.GetRealHeight(58+64), Height = dialogFra.Height - Application.GetRealHeight(58+64), Width = Application.GetRealWidth(343), }; dialogFra.AddChidren(volumeViewLayout); for (int i = 0; i < volumePlayList.Count; i++) { var player = volumePlayList[i]; #region 调节当个播放器View FrameLayout volumeFra = new FrameLayout { Height = Application.GetRealHeight(64), }; volumeViewLayout.AddChidren(volumeFra); Button volumeTextBtn = new Button { X = Application.GetRealWidth(28), Y = Application.GetRealHeight(8), Width = Application.GetRealWidth(200), Height = Application.GetRealHeight(14), TextColor = MusicColor.MusicNoTxetColor, TextSize = TextSize.Text10, TextAlignment = TextAlignment.CenterLeft, Text = player.Name + Language.StringByID(StringId.volumeMusic), }; volumeFra.AddChidren(volumeTextBtn); DiyImageSeekBar volSeekBar = new DiyImageSeekBar { Y = Application.GetRealHeight(12), X = Application.GetRealWidth(28), Width = Application.GetRealWidth(240), Height = Application.GetRealHeight(54),//进度条父控件背景高度 IsProgressTextShow = false,//显示百分比 IsClickable = true,//进度条是否滑动 ProgressBarColor = MusicColor.SelectedColor,//选中进度条颜色 ThumbImagePath = "MusicIcon/progressIcon.png",//进度条按钮图标 ThumbImageHeight = Application.GetRealWidth(54),//进度条按钮图标的高度(默认正方形:宽和高一样) SeekBarViewHeight = Application.GetRealWidth(8),//进度条的高度 Progress = int.Parse(player.A31PlayStatus.vol), SeekBarPadding = Application.GetRealWidth(20), //ProgressChangeDelayTime= }; volumeFra.AddChidren(volSeekBar); Button valueBtn = new Button { X = Application.GetRealWidth(289), Y = Application.GetRealHeight(31), Width = Application.GetRealWidth(26+15), Height = Application.GetRealHeight(17), TextColor = MusicColor.MusicNoTxetColor, TextSize = TextSize.Text12, TextAlignment = TextAlignment.CenterLeft, Text = player.A31PlayStatus.vol + "%", }; volumeFra.AddChidren(valueBtn); #endregion ///音量进度条点击事件 EventHandler<int> progressClick = (sender, e) => { if (currVolumePlay == null || (currVolumePlay != null && currVolumePlay.UniqueDeviceName != player.UniqueDeviceName)) { currVolumePlay = player; } endVolume = e; if_volume = "Volume"; valueBtn.Text = volSeekBar.Progress + "%"; }; volSeekBar.OnProgressChangedEvent += progressClick; volSeekBar.OnStopTrackingTouchEvent += progressClick; } EventHandler<int> totalProgressClick = (sender, e) => { if_volume = "totalVolume"; endVolume = e; totalVolumeValueBtn.Text = totalVolSeekBar.Progress + "%"; for (int j = 0; j < volumePlayList.Count; j++) { var music = volumePlayList[j]; var frameLayout = (FrameLayout)volumeViewLayout.GetChildren(j); var diyImageSeekBar = (DiyImageSeekBar)frameLayout.GetChildren(1); var button = (Button)frameLayout.GetChildren(2); diyImageSeekBar.Progress = totalVolSeekBar.Progress; button.Text = totalVolSeekBar.Progress + "%"; } }; totalVolSeekBar.OnProgressChangedEvent += totalProgressClick; totalVolSeekBar.OnStopTrackingTouchEvent += totalProgressClick; #endregion } /// <summary> /// 定时音量并且发送命令 /// </summary> System.Threading.Thread updateVolumeThread; public void UpdateVolume() { if (updateVolumeThread != null) { try { if (updateVolumeThread.IsAlive) { updateVolumeThread.Abort(); } } catch { } } updateVolumeThread = new System.Threading.Thread(() => { try { while (true) { System.Threading.Thread.Sleep(500); if (startVolume == endVolume) { continue; } startVolume = endVolume; if (if_volume == "totalVolume") { for (int j = 0; j < volumePlayList.Count; j++) { var music = volumePlayList[j]; //每个500毫秒发从播放器音量命令 SendMethod.ControlVolume(endVolume, music); System.Threading.Thread.Sleep(1000); } } else if(if_volume == "Volume") { if (currVolumePlay == null) { continue; } SendMethod.ControlVolume(endVolume, currVolumePlay); } } } catch { } }) { IsBackground = true }; updateVolumeThread.Start(); } } HDL_ON/UI/UI2/FuntionControlView/Music/View/MusicView.cs
@@ -10,14 +10,17 @@ /// </summary> public FrameLayout muiscFl = new FrameLayout { Name= "parentfl", Height = Application.GetRealHeight(12 + 139), Width = Application.GetRealWidth(375), }; /// <summary> ///白色背景的控件 /// </summary> public FrameLayout musicIfonFl = new FrameLayout { Name = "musicparentfl", X = Application.GetRealWidth(16), Y = Application.GetRealHeight(12), Height = Application.GetRealHeight(139), @@ -89,6 +92,7 @@ /// </summary> public Button songNameBtn = new Button { Name="song", X = Application.GetRealWidth(54), Y = Application.GetRealHeight(12), Width = Application.GetRealWidth(140), @@ -102,6 +106,7 @@ /// </summary> public Button singerBtn = new Button { Name= "singer", X = Application.GetRealWidth(54), Y = Application.GetRealHeight(36), Width = Application.GetRealWidth(120), @@ -116,6 +121,7 @@ /// </summary> public Button musicNameBtn = new Button { Name = "musicname", X = Application.GetRealWidth(54), Y = Application.GetRealHeight(40),//58 Width = Application.GetRealWidth(140), @@ -166,6 +172,7 @@ /// </summary> public Button playBtn = new Button { Tag= "playstatus", X = Application.GetRealWidth(233), Y = Application.GetRealHeight(101), Width = Application.GetRealWidth(32), @@ -189,14 +196,14 @@ /// 播放器界面的方法 /// </summary> /// <param name="verticalRefresh"></param> public void View(VerticalRefreshLayout verticalRefresh) public void ViewAddChidren(VerticalRefreshLayout verticalRefresh) { verticalRefresh.AddChidren(muiscFl); muiscFl.AddChidren(musicIfonFl); musicIfonFl.AddChidren(iconBtn); musicIfonFl.AddChidren(mergeBjBtn); musicIfonFl.AddChidren(mergeIconBtn); musicIfonFl.AddChidren(mergeBtn); //musicIfonFl.AddChidren(mergeBjBtn); //musicIfonFl.AddChidren(mergeIconBtn); //musicIfonFl.AddChidren(mergeBtn); musicIfonFl.AddChidren(collectIconBtn); musicIfonFl.AddChidren(songNameBtn); //musicIfonFl.AddChidren(singerBtn); HDL_ON/UI/UI2/FuntionControlView/Music/View/MyListView.cs
@@ -91,20 +91,21 @@ }; public void frameLayout(FrameLayout frame,A31MusicModel a31MusicModel) { switch (a31MusicModel.A31PlayStatus.loop) var mode= a31MusicModel.functionMusic.GetAttrState("mode"); switch (mode) { //0列表循环,1单曲循环,2随机播放; case "0": case "list_cycle": orderIconBtn.UnSelectedImagePath = "MusicIcon/list.png"; orderTxetBtn.Text = Language.StringByID(StringId.listMode); break; case "1": case "single_cycle/order": orderIconBtn.UnSelectedImagePath = "MusicIcon/single.png"; orderTxetBtn.Text = Language.StringByID(StringId.singleMode); break; case "2": case "random": orderIconBtn.UnSelectedImagePath = "MusicIcon/random.png"; orderTxetBtn.Text = Language.StringByID(StringId.randomMode); break; HDL_ON/UI/UI2/FuntionControlView/Music/View/PlayView.cs
@@ -14,6 +14,8 @@ Height = Application.GetRealHeight(526), Width = Application.GetRealWidth(327), BackgroundImagePath = "MusicIcon/playBj.png", Name="fl", }; /// <summary> /// 音乐汉字 @@ -28,6 +30,7 @@ TextSize = TextSize.Text24, TextAlignment = TextAlignment.CenterLeft, TextID = StringId.a31Music, Name = "musicname" }; /// <summary> /// 区域名称 @@ -41,6 +44,7 @@ TextColor = MusicColor.MusicNoTxetColor, TextSize = TextSize.Text12, TextAlignment = TextAlignment.CenterLeft, Name= "region", }; /// <summary> ///收藏图标 @@ -53,6 +57,7 @@ Height = Application.GetRealWidth(40), UnSelectedImagePath = "MusicIcon/collect.png", SelectedImagePath = "MusicIcon/collectSelected.png", Name = "collect" }; /// <summary> ///快,退进度条父控件 @@ -86,11 +91,13 @@ ArcWidth = Application.GetRealWidth(4),//进度宽度 ThumbImagePath = "MusicIcon/thumbImage.png",//进度条按钮图标 ThumbImageHeight = Application.GetMinRealAverage(8),//进度条按钮图标的高度(默认正方形:宽和高一样) MaxValue=100, MaxValue = 100, Gravity = Gravity.Center, SeekBarPadding = Application.GetMinRealAverage(3), IsClickable = false,//不可以滑动 }; /// <summary> ///音乐开始时间 /// </summary> @@ -207,6 +214,7 @@ SeekBarViewHeight = Application.GetRealWidth(8),//进度条的高度 ProgressChangeDelayTime = 300,//0.3秒发送一次 SeekBarPadding = Application.GetRealWidth(20), }; /// <summary> @@ -264,6 +272,7 @@ /// <param name="fL"></param> public void viewFrameLayout(FrameLayout fL) { fL.AddChidren(musicBjFl); musicBjFl.AddChidren(musicNameBtn); musicBjFl.AddChidren(regionBtn); HDL_ON/UI/UI2/FuntionControlView/Music/View/SongView.cs
@@ -94,39 +94,30 @@ /// 布局歌曲信息的View /// </summary> /// <returns></returns> public void SongFrameLayout(VerticalRefreshLayout refreshLayout, MusicInfo songs) public void SongFrameLayout(VerticalRefreshLayout refreshLayout, Songs songs) { musicViewFl.AddChidren(playIconBtn); musicViewFl.AddChidren(songBtn); musicViewFl.AddChidren(singerBtn); //musicViewFl.AddChidren(singerBtn); musicViewFl.AddChidren(clickBtn); musicViewFl.AddChidren(loveIcon); musicViewFl.AddChidren(addIcon); //musicViewFl.AddChidren(loveIcon); //musicViewFl.AddChidren(addIcon); refreshLayout.AddChidren(musicViewFl); playIconBtn.Tag = songs.URL; songBtn.Tag = songs.URL; singerBtn.Tag = songs.URL; songBtn.Tag = songs.name; singerBtn.Tag = songs.name; clickBtn.Tag = songs;//标记播放哪一首歌曲 songBtn.Text = string.IsNullOrEmpty(songs.Title) ? "Unkonw" : songs.Title.Trim(); songBtn.Text = string.IsNullOrEmpty(songs.name) ? "Unkonw" : songs.name.Trim(); var wText = songBtn.GetTextWidth() + Application.GetRealWidth(15); if (wText > Application.GetRealWidth(220)) if (wText > Application.GetRealWidth(250)) { wText = Application.GetRealWidth(220);//(歌曲+歌手)宽度最大值时220 wText = Application.GetRealWidth(250);//(歌曲+歌手)宽度最大值时220 } songBtn.Width = wText; singerBtn.X = songBtn.Right; singerBtn.Width = Application.GetRealWidth(220) - wText;//歌名长度小于220才可以显示歌手出来 singerBtn.Text = string.IsNullOrEmpty(songs.Artist) ? "-Unkonw" : "-" + songs.Artist.Trim(); var music = A31MusicModel.Current.LoveMusicInfoList.Find((m) => m.URL == songs.URL); if (music != null) { loveIcon.IsSelected = true; } else { loveIcon.IsSelected = false; } singerBtn.Text = string.IsNullOrEmpty(songs.name) ? "-Unkonw" : "-" + songs.name.Trim(); }