using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using Shared.SimpleControl.Phone;
|
using Shared.SimpleControl.R;
|
using SmartHome.UI.SimpleControl.Phone;
|
using System.Xml;
|
using System.Security;
|
using com.hdl.on;
|
using SmartHome;
|
using Newtonsoft.Json.Linq;
|
using Shared.SimpleControl;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class SonosMusicPage : FrameLayout
|
{
|
public override void RemoveFromParent ()
|
{
|
UserMiddle.DevicePageView.ScrollEnabled = true;
|
base.RemoveFromParent ();
|
clearA31Threads ();
|
}
|
|
/// <summary>
|
/// 加载所有音乐的滑动视图
|
/// </summary>
|
MusicVerticalScrolViewLayout verticalScrolViewLayout;
|
static List<System.Threading.Thread> threadLists = new List<System.Threading.Thread> ();
|
|
static void clearA31Threads ()
|
{
|
var threads = threadLists.FindAll ((obj) => { return obj.Name == "sonos"; });
|
foreach (var thread in threads) {
|
try {
|
threadLists.Remove (thread);
|
if (thread.IsAlive) {
|
thread.Abort ();
|
}
|
} catch (Exception e) {
|
System.Console.WriteLine (e.Message);
|
}
|
}
|
}
|
|
|
public void Show ()
|
{
|
|
UserMiddle.DevicePageView.ScrollEnabled = false;
|
|
BackgroundColor = 0xff2F2F2F;
|
var tTopFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
};
|
AddChidren (tTopFrameLayout);
|
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (100),
|
Y = tTopFrameLayout.Bottom,
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
};
|
AddChidren (topFrameLayout);
|
|
#region 总音量控制层
|
/*
|
var bottomFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (134),
|
Y = topFrameLayout.Bottom,
|
BackgroundColor = 0xFF181818,
|
};
|
//AddChidren (bottomFrameLayout);
|
|
var voiceVol = new Button {
|
Width = Application.GetRealWidth (107),
|
Height = Application.GetRealHeight (127),
|
X = Application.GetRealWidth (-3),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/PlayVoice.png",
|
};
|
bottomFrameLayout.AddChidren (voiceVol);
|
|
var frameLayoutVol = new FrameLayout {
|
Width = Application.GetRealWidth (450),
|
Height = Application.GetRealHeight (50),
|
X = Application.GetRealWidth (90),
|
Gravity = Gravity.CenterVertical,
|
};
|
bottomFrameLayout.AddChidren (frameLayoutVol);
|
|
allVol = new HorizontalSeekBar {
|
Width = Application.GetRealWidth (450 - 45),
|
Height = Application.GetRealHeight (50),
|
Radius = (uint)Application.GetRealHeight (25),
|
X = Application.GetRealWidth (13),
|
Max = 100,
|
Progress = 50,
|
SleepTime = 1000,
|
ProgressColor = 0xffFE5E00,
|
};
|
frameLayoutVol.AddChidren (allVol);
|
allVol.ProgressChanged += allVol_ProgressChanged;
|
|
muteVol = new Button {
|
Width = Application.GetRealWidth (107),
|
Height = Application.GetRealWidth (127),
|
X = Application.GetRealWidth (515),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/PlayMute.png",
|
SelectedImagePath = "MusicIcon/PlayMuteSelected.png",
|
};
|
bottomFrameLayout.AddChidren (muteVol);
|
muteVol.MouseDownEventHandler += MuteVol_MouseDownEventHandler;
|
|
var line = new Button {
|
Height = Application.GetRealHeight (4),
|
Y = topFrameLayout.Bottom,
|
UnSelectedImagePath = "MusicIcon/MusicThread.png",
|
};
|
//AddChidren (line);
|
*/
|
#endregion
|
|
FrameLayout frayout = new FrameLayout {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (1000),
|
BackgroundImagePath = "MusicIcon/MusicBackgroun.png",
|
Y = topFrameLayout.Bottom,
|
};
|
AddChidren (frayout);
|
|
|
|
#region
|
|
verticalScrolViewLayout = new MusicVerticalScrolViewLayout ();
|
verticalScrolViewLayout.ReplaceChanged += (arg1, arg2) => {
|
|
//var d = true;
|
//if (arg1.Tag.GetType () == typeof (A31MusicModel) && arg2.Tag.GetType () == typeof (A31MusicModel)) {
|
// MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.disposition) + "...");
|
// System.Threading.Tasks.Task.Run (() => {
|
// try {
|
// var serverMusic = arg1.Tag as A31MusicModel;
|
// var clientMusic = arg2.Tag as A31MusicModel;
|
|
// if (clientMusic.ServerClientType == 1) {
|
// d = false;
|
// return;
|
// }
|
// if (serverMusic.ServerClientType == -1 && clientMusic.ServerClientType == -1) {
|
// if (serverMusic.ServerIP == clientMusic.ServerIP) {
|
// d = false;
|
// return;
|
// }
|
// }
|
|
// if (serverMusic.ServerClientType == 1 && clientMusic.ServerClientType == -1) {
|
// if (serverMusic.IPAddress == clientMusic.ServerIP) {
|
// d = false;
|
// return;
|
// }
|
// }
|
|
// clearA31Threads ();
|
// var IP = "";
|
// if (serverMusic.ServerClientType == -1) {
|
// IP = serverMusic.ServerIP;
|
// } else {
|
// IP = serverMusic.IPAddress;
|
// }
|
|
// var statusEx = openWeb ("http://" + IP + "/httpapi.asp?command=getStatusEx");
|
// if (statusEx == null) {
|
// statusEx = openWeb ("http://" + IP + "/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);
|
// if (null == 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 == 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)) {
|
// return;
|
// }
|
// }
|
// System.DateTime dateTime = DateTime.Now;
|
// while ((DateTime.Now - dateTime).TotalSeconds < 10) {
|
// System.Threading.Thread.Sleep (1000);
|
// try {
|
// var result = openWeb ("http://" + serverMusic.IPAddress + "/httpapi.asp?command=multiroom:getSlaveList");
|
// if (result != null) {
|
// var tmepSlaves = Newtonsoft.Json.JsonConvert.DeserializeObject<Slaves> (result);
|
// if (tmepSlaves != null && tmepSlaves.slave_list != null) {
|
// if (null != tmepSlaves.slave_list.Find ((obj) => obj.uuid.Replace ("uuid:", "") == clientMusic.UniqueDeviceName)) {
|
// //已经添加成功
|
// break;
|
// }
|
// }
|
// }
|
// } catch (Exception e) { System.Console.WriteLine (e.Message); }
|
// }
|
|
// } catch (Exception e) { System.Console.WriteLine (e.Message); } finally {
|
// Application.RunOnMainThread (() => {
|
// MainPage.Loading.Hide ();
|
// if (d) {
|
// //this.RemoveFromParent ();
|
// //MyMusic mymusic = new MyMusic ();
|
// //MainPage.MainFrameLayout.AddChidren (mymusic);
|
// //mymusic.Show (true);
|
|
// UserMiddle.DevicePageView.PageIndex = 0;
|
// var myMusic = new MyMusic ();
|
// UserMiddle.DevicePageView.AddChidren (myMusic);
|
// myMusic.Show (true);
|
// UserMiddle.DevicePageView.PageIndex = 1;
|
|
|
// }
|
|
// });
|
// }
|
// });
|
//}
|
|
};
|
verticalScrolViewLayout.LongPressAction += (arg) => {
|
|
//if (arg.Tag.GetType () == typeof (A31MusicModel)) {
|
// var clientMusic = arg.Tag as A31MusicModel;
|
// if (clientMusic != null && clientMusic.ServerClientType == -1) {
|
// MainPage.Loading.Start ();
|
// System.Threading.Tasks.Task.Run (() => {
|
// openWeb ("http://" + clientMusic.ServerIP + "/httpapi.asp?command=multiroom:SlaveKickout:" + clientMusic.IPAddress);
|
// Application.RunOnMainThread (() => {
|
// MainPage.Loading.Hide ();
|
// //this.RemoveFromParent ();
|
// //MyMusic music = new MyMusic ();
|
// //MainPage.MainFrameLayout.AddChidren (music);
|
// //music.Show (true);
|
|
// UserMiddle.DevicePageView.PageIndex = 0;
|
// var myMusic = new MyMusic ();
|
// UserMiddle.DevicePageView.AddChidren (myMusic);
|
// myMusic.Show (true);
|
// UserMiddle.DevicePageView.PageIndex = 1;
|
|
// });
|
// });
|
// }
|
//}
|
|
};
|
|
frayout.AddChidren (verticalScrolViewLayout);
|
|
#endregion
|
|
var back = new Button {
|
Width = Application.GetMinRealAverage (72),
|
Height = Application.GetMinRealAverage (89),
|
X = Application.GetRealWidth (-1),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/MusicBack.png",
|
};
|
topFrameLayout.AddChidren (back);
|
back.MouseDownEventHandler += (sender, e) => {
|
this.RemoveFromParent ();
|
};
|
|
|
var device = new Button {
|
Width = Application.GetRealWidth (200),
|
Height = Application.GetRealHeight (60),
|
TextID = MyInternationalizationString.MusicDevicelist,
|
Gravity = Gravity.Center,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
topFrameLayout.AddChidren (device);
|
|
var a31search = new Button {
|
Width = Application.GetMinRealAverage (60),
|
Height = Application.GetMinRealAverage (80),
|
X = Application.GetRealWidth (545),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/seekdevice.png",
|
};
|
topFrameLayout.AddChidren (a31search);
|
a31search.MouseUpEventHandler += (sender, e) => {
|
|
UserMiddle.DevicePageView.PageIndex = 0;
|
var sonosMusicPage = new SonosMusicPage ();
|
UserMiddle.DevicePageView.AddChidren (sonosMusicPage);
|
sonosMusicPage.Show ();
|
UserMiddle.DevicePageView.PageIndex = 1;
|
|
};
|
|
|
//var filesList = Shared.IO.FileUtils.ReadFiles ().FindAll ((obj) => {
|
// string [] str = obj.Split ('_');
|
// return obj.StartsWith ("Equipment_") && str.Length == 5;
|
//});
|
//foreach (var file in filesList) {
|
// if (file.Split ('_') [1]!= DeviceType.SuperWireless.ToString()) {
|
// continue;
|
// }
|
// var devicestring = System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (file));
|
// if (devicestring == null) {
|
// continue;
|
// }
|
// var jObject = Newtonsoft.Json.Linq.JObject.Parse (devicestring);
|
// if (jObject == null) {
|
// continue;
|
// }
|
// SuperGateWay.GateWay gateWay = new SuperGateWay.GateWay ();
|
// gateWay.Name = jObject ["Name"]?.ToString ();
|
// gateWay.SubnetID = jObject.Value<byte> ("SubnetID");
|
// gateWay.DeviceID = jObject.Value<byte> ("DeviceID");
|
// SuperGateWay.GateWay.GateWays.Add (gateWay);
|
//}
|
|
//先判断有没有网关
|
//if (SuperGateWay.GateWay.GateWays.Count != 0) {
|
// foreach (var gateway in SuperGateWay.GateWay.GateWays) {
|
// SonosMusic.SonosMusicList.Clear ();
|
// seachsonosMusic (() => {
|
// if (SonosMusic.SonosMusicList.Count == 0) {
|
// return;
|
// }
|
// readGroup ();
|
// sonosMusicView (verticalScrolViewLayout);
|
// });
|
// }
|
//}
|
var gateWay = SuperGateWay.GateWay.gateWay ();
|
if (gateWay.Name != "GateWay_HDL_ABC") {
|
|
SuperGateWay.ScenePage.SubnetID = gateWay.SubnetID;
|
SuperGateWay.ScenePage.DeviceID = gateWay.DeviceID;
|
SonosMusic.SonosMusicList.Clear ();
|
seachsonosMusic (() => {
|
if (SonosMusic.SonosMusicList.Count == 0) {
|
return;
|
}
|
readGroup ();
|
sonosMusicView (verticalScrolViewLayout);
|
});
|
}
|
|
}
|
|
///sonos音乐
|
void sonosMusicView (MusicVerticalScrolViewLayout verticalScrolViewLayout)
|
{
|
|
|
foreach (var tempSonosMusic in SonosMusic.SonosMusicList) {
|
if (!tempSonosMusic.IsCanShow) {
|
continue;
|
}
|
|
var MusicModelBackground = new FrameLayout {
|
Width = Application.GetRealWidth (640 - 24),
|
Height = Application.GetRealHeight (190 + 20),
|
X = Application.GetRealWidth (12),
|
Y = verticalScrolViewLayout.ChildrenCount * Application.GetRealHeight (190 + 20),
|
Tag = tempSonosMusic,
|
};
|
verticalScrolViewLayout.AddChidren (MusicModelBackground);
|
|
var frameLayout = new FrameLayout {
|
// Y = Application.GetRealHeight (20) + verticalScrolViewLayout.ChildrenCount * Application.GetRealHeight (190 + 20),
|
Y = Application.GetRealHeight (20),
|
X = Application.GetRealWidth (12),
|
Width = Application.GetRealWidth (640 - 24),
|
Height = Application.GetRealHeight (190),
|
BackgroundColor = SkinStyle.Current.MusicPalyerView,
|
Tag = tempSonosMusic,
|
};
|
MusicModelBackground.AddChidren (frameLayout);
|
|
var titelFrameLayout = new FrameLayout () {
|
Height = Application.GetRealHeight (80),
|
Y = Application.GetRealHeight (3),
|
};
|
frameLayout.AddChidren (titelFrameLayout);
|
|
var Living = new Button {
|
Width = Application.GetRealWidth (300),
|
Height = Application.GetRealHeight (80),
|
Text = tempSonosMusic.name==""?"UnKown":tempSonosMusic.name,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (29),
|
Gravity = Gravity.CenterVertical,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
titelFrameLayout.AddChidren (Living);
|
|
var btntext = new Button {
|
Width = Application.GetRealWidth (100),
|
Height = Application.GetRealHeight (80),
|
//Text = "同步",
|
TextID = MyInternationalizationString.sync,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (380),
|
Gravity = Gravity.CenterVertical,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
titelFrameLayout.AddChidren (btntext);
|
btntext.MouseUpEventHandler += (sender, e) => {
|
FrameLayout flMain = new FrameLayout { BackgroundColor = 0x00000000 };
|
MainPage.MainFrameLayout.AddChidren (flMain);
|
flMain.MouseUpEventHandler += (sender12, e12) => {
|
flMain.RemoveFromParent ();
|
};
|
|
|
var btn = new Button {
|
Y = Application.GetRealHeight (Application.DesignHeight - 300 - 100 - 100),
|
Height = Application.GetRealHeight (100),
|
//Text = "添加组",
|
TextID=MyInternationalizationString.addtogroup,
|
TextSize = 16,
|
BackgroundColor = 0xff1F1F1F,
|
};
|
flMain.AddChidren (btn);
|
|
var musicnameview = new VerticalScrolViewLayout ();
|
musicnameview.Height = Application.GetRealHeight (300);
|
musicnameview.Y = Application.GetRealHeight (Application.DesignHeight - 300 - 100);
|
musicnameview.BackgroundColor = 0xff2F2F2F;//0xffffffff;
|
flMain.AddChidren (musicnameview);
|
|
|
var btncomplete = new Button {
|
Y = musicnameview.Bottom,
|
Height = Application.GetRealHeight (100),
|
TextID = MyInternationalizationString.complete,
|
TextSize = 16,
|
BackgroundColor = 0xff1F1F1F,
|
};
|
flMain.AddChidren (btncomplete);
|
|
var uidlist = new List<string> ();
|
uidlist.Clear ();
|
//foreach (var musics in SonosMusic.SonosMusicList) {
|
// if (musics.IsCanShow) {
|
// if (musics.slaves.playerIds.Count >= 2) {
|
// foreach (var uid in musics.slaves.playerIds) {
|
// uidlist.Add (uid);
|
// }
|
// }
|
// }
|
//}
|
foreach (var musics in SonosMusic.SonosMusicList) {
|
var rowmusic = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
};
|
musicnameview.AddChidren (rowmusic);
|
|
var titleMusic = new Button {
|
Width = Application.GetRealWidth (300),
|
Height = Application.GetRealHeight (100),
|
X = Application.GetRealWidth (30),
|
TextAlignment = TextAlignment.CenterLeft,
|
Gravity = Gravity.CenterVertical,
|
Text = musics.name == "" ? "UnKown" : musics.name,
|
//TextColor=0xff2F2F2F,
|
|
};
|
rowmusic.AddChidren (titleMusic);
|
|
var btnCheck = new Button {
|
Width = Application.GetRealWidth (60),
|
Height = Application.GetRealHeight (59),
|
Gravity = Gravity.CenterVertical,
|
X = Application.GetRealWidth (515),
|
SelectedImagePath = "Light/CheckOn.png",
|
UnSelectedImagePath = "Light/Check.png",
|
};
|
rowmusic.AddChidren (btnCheck);
|
|
if (tempSonosMusic.slaves.playerIds.Find ((obj) => obj == musics.uid) != null) {
|
btnCheck.IsSelected = true;
|
uidlist.Add (musics.uid);
|
|
}
|
|
|
|
EventHandler<MouseEventArgs> isselected = (sender1, e1) => {
|
btnCheck.IsSelected = !btnCheck.IsSelected;
|
if (btnCheck.IsSelected) {
|
if (!uidlist.Contains (musics.uid.ToString ())) {
|
uidlist.Add (musics.uid.ToString ());
|
}
|
} else {
|
if (uidlist.Contains (musics.uid.ToString ())) {
|
uidlist.Remove (musics.uid.ToString ());
|
}
|
}
|
};
|
|
rowmusic.MouseUpEventHandler += isselected;
|
titleMusic.MouseUpEventHandler += isselected;
|
btnCheck.MouseUpEventHandler += isselected;
|
}
|
|
|
|
|
btncomplete.MouseUpEventHandler += (sender13, e13) => {
|
|
flMain.RemoveFromParent ();
|
if (uidlist.Count == 0) {
|
uidlist.Add (tempSonosMusic.uid);
|
}
|
string sid = "";
|
try {
|
foreach (var str in tempSonosMusic.sidlist) {
|
var sidUlong = Convert.ToUInt64 (str, 16);
|
var property = (byte)((sidUlong >> 16) & 0xFF);
|
if (property == 18) {
|
sid = str;
|
break;
|
}
|
}
|
if (sid != "") {
|
var jo = new JObject ();
|
var jo1 = new JObject ();
|
var jo2 = new JObject ();
|
var jarray = new JArray ();
|
|
jo.Add ("sid", sid);
|
jo.Add ("event", jo1);
|
jo1.Add ("type", "music");
|
jo1.Add ("cmd", "setGroup");
|
jo1.Add ("cmdData", jo2);
|
jo2.Add ("playerIds", jarray);
|
jarray.Add (uidlist);
|
var command = System.Text.Encoding.UTF8.GetBytes (jo.ToString ());
|
|
var setgroupifon = Control.ControlBytesSendHasReturn (Command.SonosControl, SuperGateWay.ScenePage.SubnetID,SuperGateWay.ScenePage.DeviceID, command);
|
var dateTime = DateTime.Now;
|
while ((DateTime.Now - dateTime).TotalSeconds < 10) {
|
if (setgroupifon != null) {
|
var result = Encoding.UTF8.GetString (setgroupifon);
|
if (result != null) {
|
var jObject = JObject.Parse (result);
|
if (jObject == null) {
|
continue;
|
}
|
var Issuccess = Convert.ToBoolean (jObject ["event"] ["success"]);
|
if (Issuccess) {
|
break;
|
}
|
}
|
}
|
}
|
|
UserMiddle.DevicePageView.PageIndex = 0;
|
var sonosMusicPage = new SonosMusicPage ();
|
UserMiddle.DevicePageView.AddChidren (sonosMusicPage);
|
sonosMusicPage.Show ();
|
UserMiddle.DevicePageView.PageIndex = 1;
|
}
|
} catch { }
|
};
|
|
};
|
|
|
var btnPlayMusic = new Button {
|
Width = Application.GetRealWidth (80),
|
Height = Application.GetRealHeight (80),
|
X = Application.GetRealWidth (515),//510
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/MusicPlay.png",
|
SelectedImagePath = "MusicIcon/MusicPlaySelected.png",
|
Tag = tempSonosMusic,
|
};
|
titelFrameLayout.AddChidren (btnPlayMusic);
|
btnPlayMusic.MouseUpEventHandler += (sender, e) => {
|
Button button = (Button)sender;
|
if (button.IsSelected) {
|
button.IsSelected = false;
|
tempSonosMusic.eventsend (tempSonosMusic, 0, 2);
|
tempSonosMusic.sonosPlayStatus.playbackState = 2;
|
} else {
|
button.IsSelected = true;
|
tempSonosMusic.eventsend (tempSonosMusic, 0, 1);
|
tempSonosMusic.sonosPlayStatus.playbackState = 1;
|
}
|
};
|
|
var sonosimage = new ImageView {
|
Width = Application.GetRealWidth (80),
|
Height = Application.GetRealHeight (80),
|
X = Application.GetRealWidth (30),
|
Y = Application.GetRealHeight (220 - 130),
|
Radius = (uint)Application.GetRealHeight (8),
|
ImagePath = "MusicIcon/musicplay1.png",
|
};
|
frameLayout.AddChidren (sonosimage);
|
|
|
var currentMusic = new Button {
|
Width = Application.GetRealWidth (350),
|
Height = Application.GetRealHeight (50),
|
X = Application.GetRealWidth (135),
|
Y = Application.GetRealHeight (190 - 130),
|
TextSize = 12,
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = "UnKown",
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
frameLayout.AddChidren (currentMusic);
|
|
var currentartist = new Button {
|
Height = Application.GetRealHeight (50),
|
X = Application.GetRealWidth (135),
|
Y = Application.GetRealHeight (225 - 130),
|
TextSize = 12,
|
//TextColor = 0x80ffffff,
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = "UnKown",
|
TextColor = SkinStyle.Current.MusicArtistTextColor,
|
};
|
frameLayout.AddChidren (currentartist);
|
|
EventHandler<MouseEventArgs> CurrentPlayPage = (sender, e) => {
|
if(tempSonosMusic.ServerClientType == -1){
|
return;
|
}
|
var sonosPlay = new SonosPlay ();
|
MainPage.MainFrameLayout.AddChidren (sonosPlay);
|
sonosPlay.Show (tempSonosMusic);
|
};
|
sonosimage.MouseUpEventHandler += CurrentPlayPage;
|
currentMusic.MouseUpEventHandler += CurrentPlayPage;
|
currentartist.MouseUpEventHandler += CurrentPlayPage;
|
//Living.MouseUpEventHandler += CurrentPlayPage;
|
|
|
var voice = new Button {
|
Width = Application.GetRealWidth (33),
|
Height = Application.GetRealHeight (31),
|
X = Application.GetRealWidth (145),
|
Y = Application.GetRealHeight (275 - 130),
|
UnSelectedImagePath = "MusicIcon/MusicVoice.png",
|
};
|
frameLayout.AddChidren (voice);
|
|
var horizontalSeekBarvol = new HorizontalSeekBar {
|
Width = Application.GetRealWidth (380),
|
Height = Application.GetRealHeight (50),
|
Radius = (uint)Application.GetRealHeight (25),
|
Y = Application.GetRealHeight (275 - 140),
|
X = Application.GetRealWidth (200),
|
Max = 100,
|
Tag = tempSonosMusic,
|
ProgressColor = 0xffFE5E00,
|
ThumbRadius = 9,
|
ThumbColor = SkinStyle.Current.HorizontalSeekBarThumbColor,
|
};
|
frameLayout.AddChidren (horizontalSeekBarvol);
|
horizontalSeekBarvol.ProgressChanged += (sender, e) => {
|
tempSonosMusic.eventsend (tempSonosMusic, 28, horizontalSeekBarvol.Progress);
|
tempSonosMusic.sonosPlayStatus.vol = horizontalSeekBarvol.Progress.ToString ();
|
|
};
|
|
if (tempSonosMusic.Type == DeviceType.SonosMusic) {
|
//var music = tempSonosMusic as SonosMusic;
|
System.Threading.Tasks.Task.Run (() => {
|
System.Threading.Thread.CurrentThread.Name = "sonos";
|
threadLists.Add (System.Threading.Thread.CurrentThread);
|
var dateTime = DateTime.Now.AddSeconds (-5);
|
while (true) {
|
|
if (5 <= (DateTime.Now - dateTime).TotalSeconds) {
|
dateTime = DateTime.Now;
|
tempSonosMusic.eventsend (tempSonosMusic, 35, 999);
|
}
|
Application.RunOnMainThread (() => {
|
try {
|
|
string patn = "SonosMusicImage_";
|
if (Shared.IO.FileUtils.Exists (patn + tempSonosMusic.sonosPlayStatus.songName)) {
|
sonosimage.ImagePath = patn + tempSonosMusic.sonosPlayStatus.songName;
|
} else {
|
sonosimage.ImagePath = "MusicIcon/musicplay1.png";
|
System.Threading.Tasks.Task.Run (() => {
|
var filePath = SonosMusic.SonosMusicImage (tempSonosMusic.sonosPlayStatus.imageUrl, tempSonosMusic.sonosPlayStatus.songName);
|
if (filePath != null) {
|
Application.RunOnMainThread (() => {
|
sonosimage.ImagePath = filePath;
|
});
|
}
|
});
|
}
|
|
if (tempSonosMusic.sonosPlayStatus.playbackState == 1) {
|
btnPlayMusic.IsSelected = true;
|
} else {
|
btnPlayMusic.IsSelected = false;
|
}
|
|
//当前的音乐名称
|
currentMusic.Text = tempSonosMusic.sonosPlayStatus.songName;
|
//当前的音乐歌手
|
currentartist.Text = tempSonosMusic.sonosPlayStatus.artist;
|
|
horizontalSeekBarvol.Progress = int.Parse (tempSonosMusic.sonosPlayStatus.vol);
|
|
|
} catch (Exception e) {
|
var d = e.Message;
|
}
|
try {
|
btntext.Alpha = 1.0f;
|
btntext.Enable = true;
|
btnPlayMusic.Alpha = 1.0f;
|
btnPlayMusic.Enable = true;
|
sonosimage.Alpha = 1.0f;
|
sonosimage.Enable = true;
|
currentMusic.Alpha = 1.0f;
|
currentMusic.Enable = true;
|
currentartist.Alpha = 1.0f;
|
currentartist.Enable = true;
|
if (tempSonosMusic.ServerClientType == -1) {
|
btnPlayMusic.IsSelected = false;
|
currentMusic.Text = "";
|
currentartist.Text = "";
|
btntext.Text = "";
|
btntext.Alpha = 0.5f;
|
btntext.Enable = false;
|
btnPlayMusic.Alpha = 0.5f;
|
btnPlayMusic.Enable = false;
|
sonosimage.Alpha = 0.5f;
|
sonosimage.Enable = false;
|
currentMusic.Alpha = 0.5f;
|
currentMusic.Enable = false;
|
currentartist.Alpha = 0.5f;
|
currentartist.Enable = false;
|
}
|
} catch { }
|
});
|
//等待1秒
|
System.Threading.Thread.Sleep (500);
|
}
|
});
|
}
|
|
}
|
|
}
|
|
void readGroup (){
|
string sid = "";
|
SonosMusic SonosMusic = null;
|
try {
|
foreach (var sonosmusic in SonosMusic.SonosMusicList) {
|
SonosMusic = sonosmusic;
|
foreach (var sidstr in sonosmusic.sidlist) {
|
if (sidstr == null) {
|
continue;
|
}
|
var sidUlong = Convert.ToUInt64 (sidstr, 16);
|
var property = (byte)((sidUlong >> 16) & 0xFF);
|
if (property == 15) {
|
sid = sidstr;
|
break;
|
}
|
}
|
|
}
|
if (sid != "" && SonosMusic != null) {
|
var jo = new JObject ();
|
var jo1 = new JObject ();
|
var jo2 = new JObject ();
|
var jarray = new JArray ();
|
|
jo.Add ("sid", sid);
|
jo.Add ("event", jo1);
|
jo1.Add ("type", "music");
|
jo1.Add ("cmd", "getGroupInfo");
|
|
var command = Encoding.UTF8.GetBytes (jo.ToString ());
|
var d = Control.ControlBytesSendHasReturn (Command.SonosControl,SuperGateWay.ScenePage.SubnetID, SuperGateWay.ScenePage.DeviceID, command);
|
if (d != null) {
|
var result = Encoding.UTF8.GetString (d);
|
var jObject = JObject.Parse (result);
|
if (jObject == null) {
|
return;
|
}
|
var Issuccess = Convert.ToBoolean (jObject ["event"] ["success"]);
|
if (Issuccess) {
|
var job = jObject ["event"] ["data"];
|
var groups = job ["groups"];
|
if (groups != null) {
|
foreach (var str in groups) {
|
var ddd = Newtonsoft.Json.JsonConvert.DeserializeObject<SonosMusic.SonosSlaves> (str.ToString ());
|
if (ddd != null) {
|
var sonosmusic = SonosMusic.SonosMusicList.Find ((obj) => ddd.coordinatorId == obj.uid);
|
if (sonosmusic != null) {
|
sonosmusic.slaves = ddd;
|
//显示主播放,每一个播放器都是一个组;
|
sonosmusic.IsCanShow = true;
|
sonosmusic.ServerClientType = 0;
|
if (sonosmusic.slaves.playerIds.Count >= 2) {
|
sonosmusic.ServerClientType = 1;
|
foreach (var uid in sonosmusic.slaves.playerIds) {
|
foreach (var music in SonosMusic.SonosMusicList) {
|
if (uid == music.uid && music.uid != sonosmusic.uid) {
|
music.ServerClientType = -1;
|
music.IsCanShow = true;
|
}
|
}
|
|
}
|
}
|
|
|
}
|
}
|
}
|
}
|
|
|
}
|
|
}
|
|
}
|
} catch { }
|
}
|
///搜索sonos音乐
|
async void seachsonosMusic (Action action)
|
{
|
MainPage.Loading.Start ();
|
await System.Threading.Tasks.Task.Run (() => {
|
try {
|
var uidList = SuperGateWay.Control.GetDevicesUidList ();
|
|
if (uidList == null) {
|
return;
|
}
|
foreach (var uidstr in uidList) {
|
var number = uidstr.Substring (3, 1);
|
///判断是否是sonos音乐播放器
|
if (number == "8") {
|
var result = SuperGateWay.Control.GetDeviceByUID (uidstr.Replace (".json", ""));
|
if (result == null) {
|
continue;
|
}
|
var common = Newtonsoft.Json.JsonConvert.DeserializeObject<SuperGateWay.SuperCommon> (result);
|
if (common != null) {
|
foreach (var @object in common.objects) {
|
var functionString = @object ["function"]?.ToString ();
|
if (functionString == null) {
|
continue;
|
}
|
var functions = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Function>> (functionString);
|
if (functions == null) {
|
continue;
|
}
|
var sonosmusic = new SonosMusic ();
|
foreach (var function in functions) {
|
if (function.sid == null) {
|
continue;
|
}
|
var sidUlong = Convert.ToUInt64 (function.sid, 16);
|
var subnetId = (byte)((sidUlong >> 40) & 0xFF);
|
var deviceId = (byte)((sidUlong >> 32) & 0xFF);
|
var deviceType = (byte)((sidUlong >> 24) & 0xFF);
|
var property = (byte)((sidUlong >> 16) & 0xFF);
|
var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF);
|
var CommonLoopID = subnetId.ToString () + "_" + deviceId.ToString () + "_" + targetNumber.ToString ();
|
|
var music = SonosMusic.SonosMusicList.Find ((c) => c.CommonLoopID == CommonLoopID);
|
if (music == null) {
|
sonosmusic.SubnetID = subnetId;
|
sonosmusic.DeviceID = deviceId;
|
sonosmusic.LoopID = (byte)targetNumber;
|
sonosmusic.Type = DeviceType.SonosMusic;
|
sonosmusic.IsCanShow = true;
|
if (@object ["name"] != null) {
|
sonosmusic.name = @object ["name"]?.ToString ();
|
}
|
SonosMusic.SonosMusicList.Add (sonosmusic);
|
}
|
if (function.sid != null) {
|
sonosmusic.sidlist.Add (function.sid);
|
if (sonosmusic.sid == "") {
|
sonosmusic.sid = function.sid;
|
}
|
}
|
|
}
|
}
|
}
|
}
|
}
|
} catch { } finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
action ();
|
});
|
}
|
});
|
}
|
[System.Serializable]
|
class Function
|
{
|
public string sid;
|
public Dictionary<string, object> attr;
|
}
|
}
|
}
|