using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using Shared.SimpleControl;
|
using Shared.SimpleControl.R;
|
using Shared.SimpleControl.Pad.Music;
|
using Shared.SimpleControl.Pad;
|
using System.Xml;
|
|
namespace SmartHome.UI.SimpleControl.Pad.Music
|
{
|
class A31Tidalhome : FrameLayout
|
{
|
/// <summary>
|
/// 密码
|
/// </summary>
|
EditText password;
|
/// <summary>
|
/// 用户名
|
/// </summary>
|
EditText username;
|
A31MusicModel currentMusiceA31;
|
public void show (A31MusicModel a31)
|
{
|
currentMusiceA31 = a31;
|
AddChidren (new Button {
|
Height = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
});
|
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (90),
|
Y = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
AddChidren (topFrameLayout);
|
|
var LocallistName = new Button {
|
Text = "TIDAL LOGIN",
|
};
|
topFrameLayout.AddChidren (LocallistName);
|
|
var hdl = new Button {
|
Width = Application.GetRealWidth (154),
|
Height = Application.GetRealHeight (90),
|
X = Application.GetRealWidth (486),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = MainPage.LogoString,
|
};
|
topFrameLayout.AddChidren (hdl);
|
|
var back = new Button {
|
Width = Application.GetRealWidth (82),
|
Height = Application.GetRealHeight (89),
|
X = Application.GetRealWidth (10),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/HomepageBack.png",
|
};
|
topFrameLayout.AddChidren (back);
|
back.MouseDownEventHandler += (sender, e) => {
|
RemoveFromParent ();
|
};
|
|
var middle = new FrameLayout ();
|
middle.Y = topFrameLayout.Bottom;
|
middle.Height = Application.GetRealHeight (1136 - 130);
|
middle.BackgroundColor = 0xff2F2F2F;
|
AddChidren (middle);
|
|
username = new EditText {
|
Width = Application.GetRealWidth (580),
|
Height = Application.GetRealHeight (80),
|
X = Application.GetRealWidth (30),
|
Y = Application.GetRealHeight (180),
|
TextAlignment = TextAlignment.CenterLeft,
|
BackgroundColor = 0xFF4D4D4D,
|
};
|
middle.AddChidren (username);
|
|
password = new EditText {
|
Width = Application.GetRealWidth (580),
|
Height = Application.GetRealHeight (80),
|
X = Application.GetRealWidth (30),
|
Y = Application.GetRealHeight (300),
|
TextAlignment = TextAlignment.CenterLeft,
|
BackgroundColor = 0xFF4D4D4D,
|
};
|
middle.AddChidren (password);
|
|
Button login = new Button {
|
Width = Application.GetRealWidth (500),
|
Height = Application.GetRealHeight (100),
|
X = Application.GetRealWidth (70),
|
Y = Application.GetRealHeight (460),
|
BackgroundColor = 0xff009999,
|
Text = "Login",
|
TextSize = 18,
|
Radius = (uint)Application.GetRealHeight (16),
|
};
|
login.MouseUpEventHandler += (sender, e) => {
|
login.BackgroundColor = 0xff009999;
|
var ddd = Login (username.Text, password.Text).Replace (""", "\"");
|
if (ddd == null) {
|
return;
|
}
|
int startIndex = ddd.IndexOf ("<Result>");
|
int endIndex = ddd.IndexOf ("</Result>") + "</Result>".Length;
|
var ss = ddd.Substring (startIndex, endIndex - startIndex);
|
if (endIndex <= startIndex) {
|
return;
|
}
|
XmlDocument xml = new XmlDocument ();
|
xml.LoadXml (ss);
|
var Result = xml.SelectSingleNode ("Result").InnerText;
|
if (Result != null) {
|
// var ifTidal = Newtonsoft.Json.JsonConvert.DeserializeObject<A31Tidal>(Result);
|
|
//if (ifTidal.userMessage != "Username or password is wrong")
|
//{
|
// var list = ListReading().Replace(""", "\"");
|
|
//}
|
//else
|
//{
|
// new Tip() { Text = Language.StringByID(MyInternationalizationString.Accountorpassworderro), Direction = AMPopTipDirection.Down }.Show(login);
|
//}
|
}
|
};
|
|
login.MouseDownEventHandler += (sender, e) => {
|
login.BackgroundColor = 0xffFE5E00;
|
};
|
|
middle.AddChidren (login);
|
}
|
|
List<MusicInfo> readRadiohome (string userName, string password, string url)
|
{
|
//var userName = "ieast";
|
//var password = "60b25158ee94";
|
System.Net.WebClient webClient = new System.Net.WebClient ();
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\"");
|
webClient.Headers.Add ("Authorization", "Basic " + Convert.ToBase64String (System.Text.Encoding.ASCII.GetBytes (userName + ":" + password)));
|
System.IO.StringReader sr = null;
|
|
var airablelist = new List<MusicInfo> ();
|
try {
|
byte [] recevieBytes = webClient.DownloadData (new Uri (url));
|
string tempString = System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
sr = new System.IO.StringReader (tempString);
|
string line = null;
|
StringBuilder stringBuilder = null;
|
while ((line = sr.ReadLine ()) != null) {
|
|
line = line.Trim ();
|
if (line.StartsWith ("<code>")) {
|
stringBuilder = new StringBuilder ();
|
stringBuilder.Append ("{");
|
} else if (line.EndsWith ("</code>")) {
|
stringBuilder.Append ("}");
|
string s = @stringBuilder.ToString ().Replace (",}", "}");
|
var ariable = Newtonsoft.Json.JsonConvert.DeserializeObject<Airable> (@s);
|
stringBuilder = null;
|
MusicInfo musicInfo = new MusicInfo ();
|
musicInfo.Title = ariable.title;
|
musicInfo.URL = ariable.url;
|
for (int i = 0; i < ariable.id.Length; i++) {
|
if (ariable.id [i].ToString () == "radio") {
|
musicInfo.IsDirectory = false;
|
break;
|
}
|
}
|
airablelist.Add (musicInfo);
|
} else {
|
if (stringBuilder != null) {
|
if (line.StartsWith ("\"url\"")) {
|
line = line.Remove (line.IndexOf ("<a"), line.IndexOf ("\">") - line.IndexOf ("<a") + 2).Replace ("</a>", "");
|
stringBuilder.Append (@line);
|
} else {
|
stringBuilder.Append (@line);
|
}
|
}
|
}
|
}
|
return airablelist;
|
} catch {
|
return null;
|
} finally {
|
if (sr != null) {
|
sr.Close ();
|
}
|
|
}
|
}
|
|
/// <summary>
|
/// 登录信息
|
/// </summary>
|
/// <param name="username">用户名</param>
|
/// <param name="password">密码</param>
|
/// <returns></returns>
|
string Login (string username, string password)
|
{
|
StringBuilder getPlayList = new StringBuilder ();
|
|
getPlayList.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
|
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:UserLogin xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
|
getPlayList.AppendLine ("<AccountSource>Tidal</AccountSource>");
|
getPlayList.AppendLine ("<UserName>" + username + "</UserName>");//muzodev4
|
getPlayList.AppendLine ("<PassWord>" + password + "</PassWord>");//ECJUFDFLAICSFUAHEE
|
getPlayList.AppendLine ("<SavePass>0</SavePass>");
|
getPlayList.AppendLine ("<Code></Code>");
|
getPlayList.AppendLine ("<Proxy></Proxy>");
|
getPlayList.AppendLine ("</u:UserLogin>");
|
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#UserLogin\"");
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\"");
|
try {
|
byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + currentMusiceA31.IPAddress + ":" + currentMusiceA31.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (getPlayList.ToString ()));
|
return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
|
string ListReading ()
|
{
|
StringBuilder getPlayList = new StringBuilder ();
|
|
getPlayList.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
|
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:GetUserInfo xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
|
getPlayList.AppendLine ("<AccountSource>Tidal</AccountSource>");
|
getPlayList.AppendLine ("</u:GetUserInfo>");
|
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#GetUserInfo\"");
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\"");
|
try {
|
byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + currentMusiceA31.IPAddress + ":" + currentMusiceA31.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (getPlayList.ToString ()));
|
return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
}
|
}
|