using System; using System.Collections.Generic; using System.Text; using Shared; using Shared.SimpleControl.R; using Shared.SimpleControl.Phone.Music; using Shared.SimpleControl.Phone; using Shared.SimpleControl; namespace SmartHome.UI.SimpleControl.Phone.Music { class A31SoAaAl : FrameLayout { /// /// 列表名 /// Button listName; public void Show(A31MusicModel a31, int a, string Listname) { AddChidren(new Button { Height = Application.GetRealHeight(30), BackgroundColor = SkinStyle.Current.MainColor, }); var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight(100), Y = Application.GetRealHeight(30), BackgroundColor = SkinStyle.Current.MainColor, }; AddChidren(topFrameLayout); listName = new Button { TextID = MyInternationalizationString.LocalMusic, TextSize = 18, }; topFrameLayout.AddChidren(listName); 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 - 130); middle.BackgroundColor = 0xff2F2F2F; AddChidren(middle); #region 歌曲 if (a == 1) { listName.Text = Language.StringByID(MyInternationalizationString.LocalMusic); int number = 0; foreach (var Musicsong in MusicInfo.MusicInfoList) { number++; var rowsong = new RowLayout { Height = Application.GetRealHeight(100), }; middle.AddChidren(rowsong); var title = new Button { Width = Application.GetRealWidth(80), Height = Application.GetRealHeight(70), X = Application.GetRealWidth(10), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/PlayMusic.png", }; rowsong.AddChidren(title); var btnplayMusic = new Button { Height = Application.GetRealHeight(100), TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth(120), Gravity = Gravity.CenterVertical, Text = Musicsong.Title, Tag = number, }; rowsong.AddChidren(btnplayMusic); btnplayMusic.MouseUpEventHandler += (sender, e) => { rowsong.BackgroundColor = 0xffFE5E00; System.Threading.Tasks.Task.Run(() => { System.Threading.Thread.Sleep(100); Application.RunOnMainThread(() => { this.Parent.RemoveAt(this.Parent.ChildrenCount - 4); this.Parent.RemoveAt(this.Parent.ChildrenCount - 3); this.Parent.RemoveAt(this.Parent.ChildrenCount - 2); this.RemoveFromParent(); A31PlayMusicPage a31PlayMusic = new A31PlayMusicPage(); MainPage.MainFrameLayout.AddChidren(a31PlayMusic); a31PlayMusic.Show( MusicInfo.MusicInfoList); // a31PlayMusic.Source = "wifi"; pushList(a31, btnplayMusic.Tag, Language.StringByID(MyInternationalizationString.LocalMusic)); }); }); }; } } #endregion #region 歌手 if (a == 2) { listName.Text = Language.StringByID(MyInternationalizationString.Musicartist); var artistList = new List(); foreach (var music in MusicInfo.MusicInfoList) { if (!artistList.Contains(music.Artist)) { artistList.Add(music.Artist); } } foreach (var artist in artistList) { var rowartist = new RowLayout { Height = Application.GetRealHeight(100), }; middle.AddChidren(rowartist); var btnartist = new Button { Height = Application.GetRealHeight(100), X = Application.GetRealWidth(20), TextAlignment = TextAlignment.CenterLeft, Text = artist, }; rowartist.AddChidren(btnartist); var musicInfo = new List(); for (int j = 0; j < MusicInfo.MusicInfoList.Count; j++) { if (MusicInfo.MusicInfoList[j].Artist == btnartist.Text.ToString()) { musicInfo.Add(MusicInfo.MusicInfoList[j]); } } btnartist.MouseUpEventHandler += (sender1, e1) => { A31MusicSoAaAl a31MusicSoAaAl = new A31MusicSoAaAl(); MainPage.MainFrameLayout.AddChidren(a31MusicSoAaAl); a31MusicSoAaAl.Show(a31, artist, musicInfo); }; } } #endregion #region 专辑 if (a == 3) { listName.Text = Language.StringByID(MyInternationalizationString.Musicalbum); var albumList = new List(); foreach (var musicalbum in MusicInfo.MusicInfoList) { if (!albumList.Contains(musicalbum.Album)) { albumList.Add(musicalbum.Album); } } foreach (var album in albumList) { var rowalbum = new RowLayout { Height = Application.GetRealHeight(100), }; middle.AddChidren(rowalbum); var btnalbumName = new Button { Height = Application.GetRealHeight(100), Text = album, X = Application.GetRealWidth(20), TextAlignment = TextAlignment.CenterLeft, }; rowalbum.AddChidren(btnalbumName); var albumMusiclist = new List(); for (int i = 0; i < MusicInfo.MusicInfoList.Count; i++) { if (MusicInfo.MusicInfoList[i].Album == btnalbumName.Text.ToString()) { albumMusiclist.Add(MusicInfo.MusicInfoList[i]); } } btnalbumName.MouseUpEventHandler += (sender, e) => { A31MusicSoAaAl a31MusicSoAaAl = new A31MusicSoAaAl(); MainPage.MainFrameLayout.AddChidren(a31MusicSoAaAl); a31MusicSoAaAl.Show(a31, album, albumMusiclist); }; } } #endregion } public void pushList(A31MusicModel a31, object tag, string listName) { StringBuilder sb = new StringBuilder(); 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("<MarkSearch>0</MarkSearch>"); sb.AppendLine("<TrackNumber>" + a31.CurrentPlayMusicInfoList.Count + "</TrackNumber>"); sb.AppendLine("<Quality>0</Quality>"); sb.AppendLine("<UpdateTime>5367</UpdateTime>"); sb.AppendLine("<LastPlayIndex>2</LastPlayIndex>"); sb.AppendLine("<SwitchPageMode>0</SwitchPageMode>"); sb.AppendLine("<CurrentPage>0</CurrentPage>"); sb.AppendLine("<TotalPages>0</TotalPages>"); sb.AppendLine("</ListInfo>"); sb.AppendLine("<Tracks>"); int i = 0; foreach (var tempMusicInfo in a31.CurrentPlayMusicInfoList) { i++; sb.AppendLine("<Track" + i + ">"); sb.AppendLine("<URL>" + tempMusicInfo.URL + "</URL>"); sb.AppendLine("<Metadata>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;"); 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 id=&quot;0&quot;&gt;"); sb.AppendLine("&lt;song:subid&gt;&lt;/song:subid&gt;"); sb.AppendLine("&lt;song:description&gt;unknown&lt;/song:description&gt;"); sb.AppendLine("&lt;song:skiplimit&gt;6&lt;/song:skiplimit&gt;"); sb.AppendLine("&lt;song:id&gt;" + tempMusicInfo.ID + "&lt;/song:id&gt;"); sb.AppendLine("&lt;song:like&gt;0&lt;/song:like&gt;"); sb.AppendLine("&lt;song:singerid&gt;0&lt;/song:singerid&gt;"); sb.AppendLine("&lt;song:albumid&gt;" + tempMusicInfo.AlbumId + "&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;" + tempMusicInfo.Duration + "&quot;&gt;" + tempMusicInfo.URL + "&lt;/res&gt;"); sb.AppendLine("&lt;dc:title&gt;" + tempMusicInfo.Title + "&lt;/dc:title&gt;"); sb.AppendLine("&lt;dc:creator&gt;DJ Sanny J&lt;/dc:creator&gt;"); sb.AppendLine("&lt;upnp:artist&gt;" + tempMusicInfo.Artist + "&lt;/upnp:artist&gt;"); sb.AppendLine("&lt;upnp:album&gt;" + tempMusicInfo.Album + "&lt;/upnp:album&gt;"); sb.AppendLine("&lt;upnp:albumArtURI&gt;unknown&lt;/upnp:albumArtURI&gt;"); sb.AppendLine("&lt;/item&gt;"); sb.AppendLine("&lt;/DIDL-Lite&gt;"); sb.AppendLine("</Metadata>"); sb.AppendLine("<Id>" + tempMusicInfo.ID + "</Id>"); sb.AppendLine("<Source>iPhone5s_ttpod_search</Source>"); sb.AppendLine("<Key>" + tempMusicInfo.URL + "</Key>"); sb.AppendLine("</Track" + i + ">"); } sb.AppendLine("</Tracks>"); sb.AppendLine("</PlayList>"); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); sb.AppendLine(""); 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("" + tag + ""); 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(); 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(); 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 { } } } }