| | |
| | | FileView(dialog, verticalScrolViewLayout, musicInfo); |
| | | |
| | | } |
| | | |
| | | void FileView(Dialog dialog, VerticalScrolViewLayout verticalScrolViewLayout, MusicInfo musicInfo) |
| | | { |
| | | verticalScrolViewLayout.RemoveAll(); |
| | |
| | | for (int i = 0; i < playList1.Count; i++) |
| | | { |
| | | var musics = playList1[i]; |
| | | if (musics.A31PlayStatus.playSource == "play") |
| | | if (musics.A31PlayStatus.status == "play") |
| | | { |
| | | playList2.Add(musics); |
| | | } |
| | |
| | | //只有一个播放器在播放,默认为主播发器; |
| | | dialog.Close(); |
| | | var player = playList2[0]; |
| | | Threading(player, playList1); |
| | | MergeThreading(player, playList1); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | else |
| | | { |
| | | Threading(host_Music_If, playList1); |
| | | dialog.Close(); |
| | | MergeThreading(host_Music_If, playList1); |
| | | } |
| | | }; |
| | | } |
| | | /// <summary> |
| | | /// 选中主播放器的界面 |
| | | /// 选中某个音乐为主播放器的界面 |
| | | /// </summary> |
| | | /// <param name="musicList1">显示将要组合的播放器列表</param> |
| | | /// /// <param name="musicList2">显示在播放音乐播放器列表</param> |
| | |
| | | dialog.Close(); |
| | | |
| | | var serverMusic = selectedBtn.Tag as A31MusicModel; |
| | | Threading(serverMusic, musicList1); |
| | | MergeThreading(serverMusic, musicList1); |
| | | }; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 发送组合命令逻辑处理的方法 |
| | | /// </summary> |
| | | /// <param name="serverMusic">主播放器</param> |
| | | /// <param name="musicList1"></param> |
| | | void Threading(A31MusicModel serverMusic, List<A31MusicModel> musicList1) |
| | | { |
| | | MusicMain.loading.Start("配置中..."); |
| | | 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; |
| | | } |
| | | System.Threading.Thread.Sleep(1000);//等待一秒再发数据 |
| | | 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)) |
| | | { |
| | | |
| | | } |
| | | } |
| | | } |
| | | DateTime dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 12 * 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.UniqueDeviceName == serverMusic.UniqueDeviceName) |
| | | { |
| | | |
| | | music.ServerClientType = 1; |
| | | 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; |
| | | 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 void DetachPlayMergence(A31MusicModel a31player) |
| | | { |
| | |
| | | return; |
| | | } |
| | | dialog.Close(); |
| | | |
| | | MusicMain.loading.Start("解除中..."); |
| | | 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 && tmepSlaves.slave_list.Count == 0) |
| | | { |
| | | _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; |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | RemoveThreading(a31player, playList2); |
| | | }; |
| | | } |
| | | /// <summary> |
| | | /// 发送组合命令逻辑处理的方法 |
| | | /// </summary> |
| | | /// <param name="serverMusic">主播放器</param> |
| | | /// <param name="musicList1"></param> |
| | | void MergeThreading(A31MusicModel serverMusic, List<A31MusicModel> musicList1) |
| | | { |
| | | MusicMain.loading.Start("配置中..."); |
| | | 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.UniqueDeviceName == serverMusic.UniqueDeviceName) |
| | | { |
| | | |
| | | music.ServerClientType = 1; |
| | | 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; |
| | | 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("解除中..."); |
| | | 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) |
| | | { |
| | | host_If = false; |
| | | //子音箱与主音箱断开的命令 |
| | | 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 |
| | | { |
| | | host_If = true; |
| | | //解散组的命令 |
| | | 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 (host_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 a = 0; a < playList1.Count; a++) |
| | | { |
| | | var uuid = playList1[a].UniqueDeviceName; |
| | | 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; |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | [System.Serializable] |
| | | public class A31Wifi
{ |