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.Net; using Shared.SimpleControl; namespace SmartHome.UI.SimpleControl.Phone.Music { class A31MusicSoAaAl : FrameLayout { public void Show(A31MusicModel a31, string Listname, List musicList) { 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 listName = new Button { Text= Listname, TextColor=SkinStyle.Current.MusicTextColor, }; 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.MouseUpEventHandler+=(sender, e)=> { this.RemoveFromParent(); }; var middle = new VerticalScrolViewLayout(); middle.Y = topFrameLayout.Bottom; middle.Height = Application.GetRealHeight (Application.DesignHeight - 136); middle.BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout; AddChidren(middle); for (int i = 0; i < musicList.Count; i++) { var musicInfo = musicList [i]; var rowmisc = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (rowmisc); 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", }; rowmisc.AddChidren (title); var addlikelits = new Button { Width = Application.GetRealWidth (72), Height = Application.GetRealHeight (58), X = Application.GetRealWidth (560), UnSelectedImagePath = "MusicIcon/add.png", Gravity = Gravity.CenterVertical, }; rowmisc.AddChidren (addlikelits); addlikelits.MouseUpEventHandler += (sender1, e1) => { A31MyList A31MyList = new A31MyList (); MainPage.MainFrameLayout.AddChidren (A31MyList); A31MyList.Show (musicInfo); }; var btnplay = new Button { Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (50), Text = musicInfo.Title, TextAlignment = TextAlignment.BottomLeft, X = Application.GetRealWidth (100), Tag = musicInfo, TextColor = SkinStyle.Current.MusicTextColor, }; rowmisc.AddChidren (btnplay); var artists = new Button { Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (50), TextAlignment = TextAlignment.TopLeft, X = Application.GetRealWidth (100), Y = btnplay.Bottom, //TextColor = 0x75ffffff, Text = musicInfo.Artist + "-" + musicInfo.Album, Tag = musicInfo, TextColor = SkinStyle.Current.MusicArtistTextColor, }; rowmisc.AddChidren (artists); EventHandler musics = (sender, e) => { rowmisc.BackgroundColor = 0xffFE5E00; System.Threading.Tasks.Task.Run (() => { System.Threading.Thread.Sleep (50); Application.RunOnMainThread (() => { this.Parent.RemoveAt (this.Parent.ChildrenCount - 4); this.Parent.RemoveAt (this.Parent.ChildrenCount - 3); this.Parent.RemoveAt (this.Parent.ChildrenCount - 2); RemoveFromParent (); A31PlayMusicPage a31PlayMusicPage = new A31PlayMusicPage (); MainPage.MainFrameLayout.AddChidren (a31PlayMusicPage); a31PlayMusicPage.Show (musicList); //a31PlayMusicPage.Source = "wifi"; //a31PlayMusicPage.Source = "SONGLIST-NETWORK"; a31.A31PlayStatus.Title = btnplay.Text; System.Threading.Tasks.Task.Run (() => { pushList (a31, btnplay.Tag as MusicInfo, Listname); }); }); }); }; btnplay.MouseUpEventHandler += musics; artists.MouseUpEventHandler += musics; } } public void pushList (A31MusicModel a31, MusicInfo musicInfo, string listName) { //最大发送的条数 int maxCount =50; //找出当前点击音乐的索引 int statIndex = A31MusicModel.Current.CurrentPlayMusicInfoList.FindIndex ((obj) => { return obj == musicInfo; }); //点击后面还有多少条音乐 int count = A31MusicModel.Current.CurrentPlayMusicInfoList.Count - statIndex; int endIndex = 0; if (maxCount < count) { //如果后面的音乐大于最大数,设置后面数据的最大索引 endIndex = statIndex + maxCount - 1; } else { //如果后面数据不多,就用总数减去最大条数,得到开始索引 statIndex = A31MusicModel.Current.CurrentPlayMusicInfoList.Count - maxCount - 1; endIndex = A31MusicModel.Current.CurrentPlayMusicInfoList.Count - 1; } //如果开始索引小于0,那就设置为第一条音乐 if (statIndex < 0) { statIndex = 0; } 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>" + (endIndex - statIndex +1) + "</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 playNumber = 1; for (int trackNumber = 1, index = statIndex; index <= endIndex; trackNumber++, index++) { var tempMusicInfo = a31.CurrentPlayMusicInfoList [index]; //找出当前音乐播放的序号 if (musicInfo == tempMusicInfo) { playNumber = trackNumber; } if (tempMusicInfo.SourceType == "Local") { tempMusicInfo.URL = "http://" + new NetWiFi ().IpAddress + ":" + com.hdl.on.Server.Port + "/" + tempMusicInfo.ID; } sb.AppendLine ("<Track" + trackNumber + ">"); 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;" +index+ "&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>" +index + "</Id>"); sb.AppendLine ("<Source>iPhone5s_ttpod_search</Source>"); sb.AppendLine ("<Key>" + tempMusicInfo.URL + "</Key>"); sb.AppendLine ("</Track" + trackNumber + ">"); } 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 ("" + playNumber + ""); 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 { } } } }