using System; using System.Collections.Generic; using System.Text; using Shared; using Shared.SimpleControl.R; using System.Xml; using Shared.SimpleControl.Phone; using Shared.SimpleControl.Phone.Music; using Shared.SimpleControl; namespace SmartHome.UI.SimpleControl.Phone.Music { class A31Pandora : FrameLayout { A31MusicModel currentMusiceA31; public void show (A31MusicModel a31) { currentMusiceA31 = a31; AddChidren (new Button { Height = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MusicTopFrameLayout, }); var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight (100), Y = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MusicTopFrameLayout, }; AddChidren (topFrameLayout); var RadiolistName = new Button { TextID = MyInternationalizationString.PANDORA, TextColor=SkinStyle.Current.MusicTextColor, }; topFrameLayout.AddChidren (RadiolistName); 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 frameLayout = new FrameLayout { Height = Application.GetRealHeight (Application.DesignHeight - 136), Y = Application.GetRealHeight (136), //BackgroundColor = 0xff2F2F2F, BackgroundColor=SkinStyle.Current.MusicVerticalScrolViewLayout, }; AddChidren (frameLayout); var tologin = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Tologin, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (25), Y = Application.GetRealHeight (10), TextColor = SkinStyle.Current.MusicTextColor, }; frameLayout.AddChidren (tologin); //用户名 var username = new EditText { Width = Application.GetRealWidth (590), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (25), Y = Application.GetRealHeight (130), TextAlignment = TextAlignment.Center, //Radius = (uint)Application.GetRealHeight(6), BackgroundColor= SkinStyle.Current.MusicEditTextBackgroundColor, PlaceholderText = Language.StringByID (MyInternationalizationString.Youremail), PlaceholderTextColor =SkinStyle.Current.MusicEditTextPlaceholderTextColor, TextColor = SkinStyle.Current.MusicTextColor, BorderWidth = 2, BorderColor = SkinStyle.Current.MusicEditBorderColor, Radius = 2, }; frameLayout.AddChidren (username); //密码 var password = new EditText { Width = Application.GetRealWidth (590), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (25), Y = Application.GetRealHeight (230), TextAlignment = TextAlignment.Center, //Radius = (uint)Application.GetRealHeight(6), BackgroundColor = SkinStyle.Current.MusicEditTextBackgroundColor, SecureTextEntry = true, PlaceholderText = Language.StringByID (MyInternationalizationString.Yourpassword), PlaceholderTextColor = SkinStyle.Current.MusicEditTextPlaceholderTextColor, TextColor = SkinStyle.Current.MusicTextColor, BorderWidth = 2, BorderColor = SkinStyle.Current.MusicEditBorderColor, Radius = 2, }; 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), TextColor = SkinStyle.Current.MusicTextColor, }; frameLayout.AddChidren (notologin); //登录 Button login = new Button { Width = Application.GetRealWidth (590), Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.login, TextSize = 18, X = Application.GetRealWidth (25), Y = Application.GetRealHeight (450), BackgroundColor = 0xff656565, //TextColor = SkinStyle.Current.MusicTextColor, }; frameLayout.AddChidren (login); login.MouseUpEventHandler += (sender, e) => { login.BackgroundColor = 0xff656565; 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 ()); 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 (); MainPage.MainFrameLayout.AddChidren (a31PandoraList); a31PandoraList.show (a31, pandoraConfig.UserName, pandoraConfig.Passwrod); }); }); } } 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 startIndex4 = pandoraString.IndexOf (""); int endIndex = pandoraString.IndexOf ("") + "".Length; if (endIndex <= startIndex4) { continue; } var ss = pandoraString.Substring (startIndex4, endIndex - startIndex4); 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 (""); Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); 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 (""); Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); 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 (""); Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); 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) { Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); 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 { } } } }