using System; using System.Collections.Generic; using System.Text; using Shared; using Shared.SimpleControl.R; using System.Xml; using Shared.SimpleControl; using Shared.SimpleControl.Pad.Music; namespace SmartHome.UI.SimpleControl.Pad.Music { class A31Pandora : FrameLayout { A31MusicModel currentMusiceA31; public void show(A31MusicModel a31,FrameLayout SettingView,FrameLayout PalyPage) { currentMusiceA31 = a31; var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight(100), BackgroundColor = SkinStyle.Current.MainColor, }; AddChidren(topFrameLayout); var RadiolistName = new Button { TextID = MyInternationalizationString.PANDORA, }; topFrameLayout.AddChidren(RadiolistName); 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 frameLayout = new FrameLayout { Height = Application.GetRealHeight(Application.DesignHeight - 100-150), Y = topFrameLayout.Bottom, BackgroundColor = 0xff2F2F2F, }; AddChidren(frameLayout); var tologin = new Button { Height = Application.GetRealHeight(100), TextID = MyInternationalizationString.Tologin, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth(25), Y = Application.GetRealHeight(10), }; frameLayout.AddChidren(tologin); //用户名 var username = new EditText { Width = Application.GetRealWidth(528), Height = Application.GetRealHeight(80), X = Application.GetRealWidth(25), Y = Application.GetRealHeight(130), TextAlignment = TextAlignment.CenterLeft, //Radius = (uint)Application.GetRealHeight(6), BackgroundColor = 0xFF4D4D4D, }; frameLayout.AddChidren(username); //密码 var password = new EditText { Width = Application.GetRealWidth(528), Height = Application.GetRealHeight(80), X = Application.GetRealWidth(25), Y = Application.GetRealHeight(230), TextAlignment = TextAlignment.CenterLeft, //Radius = (uint)Application.GetRealHeight(6), BackgroundColor = 0xFF4D4D4D, SecureTextEntry = true, }; frameLayout.AddChidren(password); var notologin = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Toregister, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (25), Y = Application.GetRealHeight (350), }; frameLayout.AddChidren(notologin); //登陆 Button login = new Button { Width = Application.GetRealWidth(528), Height = Application.GetRealHeight(100), TextID = MyInternationalizationString.login, TextSize = 18, X = Application.GetRealWidth(25), Y = Application.GetRealHeight(450), BackgroundColor = 0xff009999, //Radius = (uint)Application.GetRealHeight(6), }; frameLayout.AddChidren(login); login.MouseUpEventHandler += (sender, e) => { login.BackgroundColor = 0xff009999; if (username.Text.Trim () == "" || password.Text.Trim () == "") { new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.TipPleaseEnterTheCorrectData), Language.StringByID (MyInternationalizationString.Close)).Show (); return; } MainPage.Loading.Start ("Loging..."); var temusername = username.Text; var tempassword = password.Text; System.Threading.Tasks.Task.Run (() => { var result = loginPadora (a31, temusername, tempassword); Application.RunOnMainThread (() => { MainPage.Loading.Hide (); switch (result) { case 1: RemoveFromParent (); MainPage.AddTip (Language.StringByID (MyInternationalizationString.successful), 1000); A31PandoraList a31Pandoralist = new A31PandoraList (); MainPage.MainFrameLayout.AddChidren (a31Pandoralist); a31Pandoralist.show (a31, username.Text.Trim (), password.Text.Trim (), SettingView, PalyPage); break; case 3: new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.Accountorpassworderro), Language.StringByID (MyInternationalizationString.Close)).Show (); break; default: new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.networkerrors), Language.StringByID (MyInternationalizationString.Close)).Show (); break; } }); }); }; login.MouseDownEventHandler += (sender, e) => { login.BackgroundColor = 0xffFE5E00; }; var pandoraConfig = Newtonsoft.Json.JsonConvert.DeserializeObject(System.Text.Encoding.UTF8.GetString(Shared.IO.FileUtils.ReadFile(PandoraConfig.FileName))); if (pandoraConfig != null) { MainPage.Loading.Start(); username.Text = pandoraConfig.UserName; password.Text = pandoraConfig.Passwrod; System.Threading.Tasks.Task.Run(() => { //loginPadora(a31, pandoraConfig.UserName, pandoraConfig.Passwrod); readList(a31, pandoraConfig.UserName, pandoraConfig.Passwrod); Application.RunOnMainThread(() => { MainPage.Loading.Hide(); RemoveFromParent(); A31PandoraList a31PandoraList = new A31PandoraList(); SettingView.AddChidren (a31PandoraList); a31PandoraList.show(a31, pandoraConfig.UserName, pandoraConfig.Passwrod,SettingView, PalyPage); }); }); } } int loginPadora (A31MusicModel a31, string username, string password) { int result = 0; try { var dd = Login (username, password); System.DateTime dateTime = DateTime.Now; while ((DateTime.Now - dateTime).TotalMilliseconds < 9 * 1000) { System.Threading.Thread.Sleep (500); var pandoraString = readList (); if (pandoraString == null) { continue; } pandoraString = pandoraString.Replace ("&", "&").Replace ("<", "<").Replace (">", ">").Replace (""", "\"").Replace ("", "").Replace ("<", "").Replace (">", "").Replace ("&", "").Replace (""", ""); int startIndex = pandoraString.IndexOf (""); int endIndex = pandoraString.IndexOf ("") + "".Length; if (endIndex <= startIndex) { continue; } var ss = pandoraString.Substring (startIndex, endIndex - startIndex); XmlDocument xml = new XmlDocument (); xml.LoadXml (ss); var playList = xml.SelectSingleNode ("PlayList"); var listNameP = playList.SelectSingleNode ("ListName").InnerText; var listInfo = playList.SelectSingleNode ("ListInfo"); result = int.Parse (listInfo.SelectSingleNode ("MarkSearch").InnerText); if (result == 1) { readList (a31, username, password); break; } } } catch { } return result; } void readList(A31MusicModel a31, string username, string password) { var pandoraListString = PandoraList(); if (pandoraListString == null) { return; } pandoraListString = pandoraListString.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace(""", "\"").Replace("", "").Replace("<", "").Replace(">", "").Replace("&", "").Replace(""", ""); int startIndex1 = pandoraListString.IndexOf(""); int endIndex1 = pandoraListString.IndexOf("") + "".Length; var aa = pandoraListString.Substring(startIndex1, endIndex1 - startIndex1); if (endIndex1 <= startIndex1) { return; } XmlDocument xml1 = new XmlDocument(); xml1.LoadXml(aa); var pandoraList = xml1.SelectSingleNode("PlayQueue"); int number1 = int.Parse(pandoraList.SelectSingleNode("TotalQueue").InnerText); var playListInfo = pandoraList.SelectSingleNode("PlayListInfo"); a31.PanRadioInfoList.Clear(); for (int i = 1; i <= number1; i++) { var list = playListInfo.SelectSingleNode("List" + i); MusicInfo musicInfo = new MusicInfo(); musicInfo.Title = list.SelectSingleNode("Name").InnerText; var ListInfo = list.SelectSingleNode("ListInfo"); foreach (XmlNode childNode in ListInfo.ChildNodes) { switch (childNode.Name) { case "SearchUrl": musicInfo.URL = childNode.InnerText; break; case "StationID": musicInfo.ID = childNode.InnerText; break; case "PicUrl": #region 初始化网络图片路径 string path = ""; if (Shared.Application.IsPad) { path = "Pad/" + "MusicImage/"; } else { path = "Phone/" + "MusicImage/"; } path = System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, path + childNode.InnerText.Replace('/', '_').Replace('\\', '_').Replace(':', '_').Replace('*', '_').Replace('?', '_').Replace('"', '_').Replace('<', '_').Replace('>', '_').Replace('|', '_')); musicInfo.Image = path; #endregion Shared.IO.FileUtils.DownLoadImage(musicInfo.Image, childNode.InnerText); //musicInfo.Image = childNode.InnerText; break; } } if (musicInfo.ID == null) { continue; } currentMusiceA31.PanRadioInfoList.Add(musicInfo); } var pandoraConfigBytes = System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(new PandoraConfig { UserName = username, Passwrod = password })); Shared.IO.FileUtils.WriteFileByBytes(PandoraConfig.FileName, pandoraConfigBytes); } /// /// 登录信息 /// /// 用户名 /// 密码 /// string Login(string username, string password) { StringBuilder getPlayList = new StringBuilder(); getPlayList.AppendLine(""); getPlayList.AppendLine(""); getPlayList.AppendLine(""); getPlayList.AppendLine(""); getPlayList.AppendLine(""); getPlayList.AppendLine("<?xml version="1.0"?>"); getPlayList.AppendLine("<PlayList>"); getPlayList.AppendLine("<ListName>Pandora</ListName>"); getPlayList.AppendLine("<ListInfo>"); getPlayList.AppendLine("<TrackNumber>0</TrackNumber>"); getPlayList.AppendLine("<SearchUrl>tuner.pandora.com</SearchUrl>"); getPlayList.AppendLine("<Quality>0</Quality>"); getPlayList.AppendLine("<UpdateTime>0</UpdateTime>"); getPlayList.AppendLine("<Http_proxy></Http_proxy>"); getPlayList.AppendLine("<Login_username>" + username + "</Login_username>");//2532767200@qq.com getPlayList.AppendLine("<Login_password>" + password + "</Login_password>");//85521566 getPlayList.AppendLine("</ListInfo>"); getPlayList.AppendLine("</PlayList>"); getPlayList.AppendLine(""); getPlayList.AppendLine(""); getPlayList.AppendLine(""); getPlayList.AppendLine(""); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Headers.Add("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BackUpQueue\""); 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 readList() { StringBuilder ss = new StringBuilder(); ss.AppendLine(""); ss.AppendLine(""); ss.AppendLine(""); ss.AppendLine(""); ss.AppendLine("Pandora"); ss.AppendLine(""); ss.AppendLine(""); ss.AppendLine(""); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Proxy = null; webClient.Headers.Add("CONTENT-TYPE", "text/xml;charset=\"utf-8\""); webClient.Headers.Add("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BrowseQueue\""); try { byte[] recevieBytes = webClient.UploadData(new Uri("http://" + currentMusiceA31.IPAddress + ":" + currentMusiceA31.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(ss.ToString())); return System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); } catch (Exception e) { return null; } } /// /// 获取电台列表信息 /// /// 列表名 /// string PandoraList() { StringBuilder stringList = new StringBuilder(); stringList.AppendLine(""); stringList.AppendLine(""); stringList.AppendLine(""); stringList.AppendLine(""); stringList.AppendLine("TotalQueue"); stringList.AppendLine(""); stringList.AppendLine(""); stringList.AppendLine(""); System.Net.WebClient webClient = new System.Net.WebClient(); webClient.Proxy = null; webClient.Headers.Add("CONTENT-TYPE", "text/xml;charset=\"utf-8\""); webClient.Headers.Add("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BrowseQueue\""); try { byte[] recevieBytes = webClient.UploadData(new Uri("http://" + currentMusiceA31.IPAddress + ":" + currentMusiceA31.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(stringList.ToString())); return System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); } catch (Exception e) { return null; } } public void pushList(A31MusicModel a31, object tag, string listName) { StringBuilder playString = new StringBuilder(); playString.AppendLine(""); playString.AppendLine(""); playString.AppendLine(""); playString.AppendLine(""); playString.AppendLine("" + listName + ""); playString.AppendLine("1"); playString.AppendLine(""); playString.AppendLine(""); playString.AppendLine(""); play(a31.IPAddress, a31.Port, playString.ToString()); } 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); } catch { } } } }