using System; using System.Collections.Generic; using System.Text; using Shared; using Shared.SimpleControl; using Shared.SimpleControl.Phone; using Shared.SimpleControl.Phone.Music; using Shared.SimpleControl.R; namespace SmartHome.UI.SimpleControl.Phone.Music { class A31RadioList : FrameLayout { /// /// 判断是否可以直接播放 /// /// /// bool isRadios (object [] ob) { bool result = false; foreach (object o in ob) { if (o.ToString () == "radio") { result = true; break; } else if (o.ToString () == "feed.episode") { result = true; break; } else if (o.ToString () == "track") { result = true; break; } } return result; } public void show (A31MusicModel a31, Airable airable, string currname) { 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 = currname, }; 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 VerticalScrolViewLayout (); middle.Y = topFrameLayout.Bottom; middle.Height = Application.GetRealHeight (Application.DesignHeight - 126); middle.BackgroundColor = 0xff2F2F2F; AddChidren (middle); if (airable == null) { return; } if (airable.content == null) { return; } if (airable.content.entries == null) { return; } int munber = 0; a31.CnRadioInfoList = new List (); foreach (var entrie in airable.content.entries) { if (isRadios (entrie.id)) { a31.CnRadioInfoList.Add (new MusicInfo { URL = entrie.url, Title = entrie.title }); var rowsong = new RowLayout { Height = Application.GetRealHeight (100), }; middle.AddChidren (rowsong); var title = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (61), X = Application.GetRealWidth (20), Gravity = Gravity.CenterVertical, Radius = (uint)Application.GetRealHeight (4), UnSelectedImagePath = "MusicIcon/musicplay1.png", }; rowsong.AddChidren (title); var radioname = new Button { Width = Application.GetRealWidth (400), Text = entrie.title, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Tag = munber++, }; rowsong.AddChidren (radioname); radioname.MouseUpEventHandler += (sender, e) => { rowsong.BackgroundColor = 0xffFE5E00; System.Threading.Tasks.Task.Run (() => { System.Threading.Thread.Sleep (10); Application.RunOnMainThread (() => { for (int i = MainPage.MainFrameLayout.ChildrenCount - 1; 0 <= i; i--) { var view = MainPage.MainFrameLayout.GetChildren (i); if (view.GetType () == typeof (A31RadioList)) { view.RemoveFromParent (); } else { break; } } MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1); MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1); MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1); A31PlayMusicPage a31playmusic = new A31PlayMusicPage (); MainPage.MainFrameLayout.AddChidren (a31playmusic); a31playmusic.Show (new List ()); //a31playmusic.Source = "RADIO-NETWORK"; a31.A31PlayStatus.Title = radioname.Text; System.Threading.Tasks.Task.Run (() => { pushList (a31, radioname.Tag, currname); }); }); }); }; } else { //目录列表 if (entrie.title != "搜索" || entrie.title != "Suche") { var rowtrue = new RowLayout { Height = Application.GetRealHeight (100) }; middle.AddChidren (rowtrue); var radius = new Button { Width = Application.GetRealWidth (36), Height = Application.GetRealHeight (36), TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (20), UnSelectedImagePath = "MusicIcon/radius.png", Gravity = Gravity.CenterVertical, }; rowtrue.AddChidren (radius); var radioname = new Button { Width = Application.GetRealWidth (440), Gravity = Gravity.CenterVertical, Text = entrie.title, X = Application.GetRealWidth (80), TextAlignment = TextAlignment.CenterLeft, Tag = entrie.url, }; rowtrue.AddChidren (radioname); var radionext = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), }; rowtrue.AddChidren (radionext); EventHandler useshare = (sender, e) => { var radioConfig = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (RadioConfig.FileName))); MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { Airable airablelist = null; try { airablelist = A31CommonLogin.ReadRadiohome (radioConfig.UserName, radioConfig.Passwrod, radioname.Tag.ToString ()); if (airablelist == null) { airablelist = A31CommonLogin.ReadRadiohome (radioConfig.UserName, radioConfig.Passwrod, radioname.Tag.ToString ()); } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31RadioList a31RadioList = new A31RadioList (); MainPage.MainFrameLayout.AddChidren (a31RadioList); a31RadioList.show (a31, airablelist, radioname.Text); }); } }); }; radius.MouseUpEventHandler += useshare; radioname.MouseUpEventHandler += useshare; radionext.MouseUpEventHandler += useshare; } #region .......搜索 ////.......搜索 //else //{ // var searchrowtrue = new RowLayout // { // Height = Application.GetRealHeight(100) // }; // middle.AddChidren(searchrowtrue); // var radius = new Button // { // Width = Application.GetRealWidth(36), // Height = Application.GetRealHeight(36), // TextAlignment = TextAlignment.CenterLeft, // X = Application.GetRealWidth(20), // UnSelectedImagePath = "MusicIcon/radius.png", // Gravity = Gravity.CenterVertical, // }; // searchrowtrue.AddChidren(radius); // var search = new Button // { // Gravity = Gravity.CenterVertical, // Text = entrie.title, // X = Application.GetRealWidth(80), // TextAlignment = TextAlignment.CenterLeft, // Tag = entrie.url, // }; // searchrowtrue.AddChidren(search); // var searchnext = new Button // { // Width = Application.GetRealWidth(87), // Height = Application.GetRealHeight(100), // UnSelectedImagePath = "MusicIcon/Next.png", // SelectedImagePath = "MusicIcon/NextSelecte.png", // X = Application.GetRealWidth(550), // }; // searchrowtrue.AddChidren(searchnext); // EventHandler searchs = (sender, e) => // { // A31Search A31search = new A31Search(); // MainPage.MainFrameLayout.AddChidren(A31search); // A31search.Show(a31); // }; // radius.MouseUpEventHandler += searchs; // search.MouseUpEventHandler += searchs; // searchnext.MouseUpEventHandler += searchs; //} #endregion } } } public static string GetPlayUrl (string url) { System.DateTime dateTime = DateTime.Now; var radioConfig = Newtonsoft.Json.JsonConvert.DeserializeObject (System.Text.Encoding.UTF8.GetString (Shared.IO.FileUtils.ReadFile (RadioConfig.FileName))); var airable = A31CommonLogin.ReadRadiohome (radioConfig.UserName, radioConfig.Passwrod, url); if (airable != null && airable.streams != null) { airable = A31CommonLogin.ReadRadiohome (radioConfig.UserName, radioConfig.Passwrod, airable.streams [0].url); if (airable == null) { airable = A31CommonLogin.ReadRadiohome (radioConfig.UserName, radioConfig.Passwrod, airable.streams [0].url); } } if (airable == null) { return ""; } else { return airable.url; } } public void pushList (A31MusicModel a31, object tag, string listName) { StringBuilder sb = new StringBuilder (); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine ("<?xml version="1.0" ?>"); sb.AppendLine ("<PlayList>"); sb.AppendLine ("<ListName>" + listName + "</ListName>"); sb.AppendLine ("<ListInfo>"); sb.AppendLine ("<SourceName></SourceName>"); sb.AppendLine ("<TrackNumber>1</TrackNumber>"); sb.AppendLine ("<SearchUrl>searchurl</SearchUrl>"); sb.AppendLine ("</ListInfo>"); sb.AppendLine ("<Tracks>"); var tempMusicInfo = a31.CnRadioInfoList [int.Parse (tag.ToString ())]; string url = GetPlayUrl (tempMusicInfo.URL); sb.AppendLine ("<Track" + 1 + ">"); sb.AppendLine ("<URL>" + url + "</URL>"); sb.AppendLine ("<Source></Source>"); sb.AppendLine ("<Metadata>"); sb.AppendLine ("&lt;DIDL-Lite xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; xmlns:upnp=&quot;urn:schemas-upnp-org:metadata-1-0/upnp/&quot; xmlns:song=&quot;www.wiimu.com/song/&quot; xmlns=&quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&quot;&gt;"); sb.AppendLine ("&lt;upnp:class&gt;object.item.audioItem.musicTrack&lt;/upnp:class&gt;"); sb.AppendLine ("&lt;item&gt;"); sb.AppendLine ("&lt;song:bitrate&gt;0&lt;/song:bitrate&gt;"); sb.AppendLine ("&lt;song:id&gt;0&lt;/song:id&gt;"); sb.AppendLine ("&lt;song:singerid&gt;0&lt;/song:singerid&gt;"); sb.AppendLine ("&lt;song:albumid&gt;0&lt;/song:albumid&gt;"); sb.AppendLine ("&lt;res protocolInfo=&quot;http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;&quot; duration=&quot;1000&quot;&gt;" + url + "&lt;/res&gt;"); sb.AppendLine ("&lt;dc:title&gt;" + tempMusicInfo.Title + "&lt;/dc:title&gt;"); sb.AppendLine ("&lt;upnp:artist&gt;TuneIn&lt;/upnp:artist&gt;"); sb.AppendLine ("&lt;upnp:album&gt;&lt;/upnp:album&gt;"); sb.AppendLine ("&lt;upnp:albumArtURI&gt;" + tempMusicInfo.Image + "&lt;/upnp:albumArtURI&gt;"); sb.AppendLine ("&lt;/item&gt;"); sb.AppendLine ("&lt;/DIDL-Lite&gt;"); sb.AppendLine ("</Metadata>"); sb.AppendLine ("</Track" + 1 + ">"); sb.AppendLine ("</Tracks>"); sb.AppendLine ("</PlayList>"); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); sb.AppendLine (""); //sendMusicLists(a31.IPAddress, a31.Port, "CreateQueue", sb.ToString()); sendMusicLists (a31.IPAddress, a31.Port, "CreateQueue", sb.ToString ()); 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 sendMusicLists (string ip, int port, string soapAction, string listInfo) { Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (5000); webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#" + soapAction + "\""); 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 (listInfo)); var s = System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length); } catch { } } void play (string ip, int port, string info) { Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (5000); 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 { } } } }