using System; using System.Collections.Generic; using System.Text; using Shared; using Shared.SimpleControl.Phone; using Shared.SimpleControl; using Shared.SimpleControl.R; using System.Xml; using SmartHome.UI.SimpleControl.Phone.Music; using System.Security; using SmartHome; using System.Net; using System.Security.Cryptography; namespace Shared.SimpleControl.Phone.Music { /// /// 音乐源界面 /// class A31MusicSourcePage : FrameLayout { A31MusicModel a31MusicModel; public void Show (A31MusicModel a31) { a31MusicModel = a31; AddChidren (new Button { Height = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MusicTopFrameLayout, }); var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight (90), Y = Application.GetRealHeight (36), BackgroundColor = SkinStyle.Current.MusicTopFrameLayout, }; AddChidren (topFrameLayout); var btnTitle = new Button { TextID = MyInternationalizationString.MusicSource, TextColor = SkinStyle.Current.MusicTextColor, //TextSize = 20, }; topFrameLayout.AddChidren (btnTitle); 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 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 tempFrameLayout = new FrameLayout { Y = topFrameLayout.Bottom, Height = Application.GetRealHeight (Application.DesignHeight - 126), //BackgroundImagePath = "MusicIcon/HomepageBackgroun.png", BackgroundColor=SkinStyle.Current.MusicVerticalScrolViewLayout, }; AddChidren (tempFrameLayout); VerticalScrolViewLayout middle = new VerticalScrolViewLayout (); tempFrameLayout.AddChidren (middle); #region 本地音乐 var LocalMusic = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (LocalMusic); //var btnLocalMusicLine = new Button () { // Y = Application.GetRealHeight (100)-1, // Height = 1, // BackgroundColor = SkinStyle.Current.LineColor, //}; //LocalMusic.AddChidren (btnLocalMusicLine); //if (Application.DeviceType == Device.Android) { //middle.AddChidren (LocalMusic); //} var musichoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/musicMusic.png", SelectedImagePath = "MusicIcon/HomepageMusicSelected.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; LocalMusic.AddChidren (musichoto); var musicSD = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Musicmusic, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; LocalMusic.AddChidren (musicSD); var nextSD = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), }; LocalMusic.AddChidren (nextSD); EventHandler LocalMusicource = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31LocalMusic a31Music = new A31LocalMusic (); MainPage.MainFrameLayout.AddChidren (a31Music); a31Music.Show (a31); }); }); }; LocalMusic.MouseUpEventHandler += LocalMusicource; musicSD.MouseUpEventHandler += LocalMusicource; nextSD.MouseUpEventHandler += LocalMusicource; musichoto.MouseUpEventHandler += LocalMusicource; #endregion #region USB var USBrowlayout = new RowLayout { Height = Application.GetRealHeight (100), LineColor=SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (USBrowlayout); var USBhoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/USB.png", SelectedImagePath = "MusicIcon/USBselected.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; USBrowlayout.AddChidren (USBhoto); var usb = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.MuiscUSB, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; USBrowlayout.AddChidren (usb); var usbSD = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), }; USBrowlayout.AddChidren (usbSD); EventHandler USBsource = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { var musicInfoList = new List (); try { //var dd = usbserarchSong (a31.IPAddress); var usbString = getUSBPlayList (); if (usbString == null) { return; } var se = System.Security.SecurityElement.FromString (usbString); while (se.Children != null) { se = se.Children [0] as System.Security.SecurityElement; } foreach (SecurityElement track in SecurityElement.FromString (se.Text).SearchForChildByTag ("Tracks").Children) { MusicInfo musicInfo = new MusicInfo (); musicInfo.URL = track.SearchForTextOfTag ("URL"); var metadata = track.SearchForTextOfTag ("Metadata").Replace ("&", "&"); var item = SecurityElement.FromString (metadata).SearchForChildByTag ("item"); musicInfo.Title = item.SearchForTextOfTag ("dc:title"); musicInfo.Artist = item.SearchForTextOfTag ("upnp:artist"); musicInfo.Album = item.SearchForTextOfTag ("upnp:album"); musicInfo.Duration = item.SearchForTextOfTag ("res"); musicInfo.AlbumId = item.SearchForTextOfTag ("song:albumid"); musicInfoList.Add (musicInfo); } /* var songList = Newtonsoft.Json.JsonConvert.DeserializeObject (dd); foreach (var v in songList.infolist) { byte [] bytes = new byte [v.Title.Length / 2]; for (int i = 0, j = 0; i < bytes.Length; j += 2, i++) { //把16进度转换成byte // bytes [i] = Convert.ToByte (v.Title.Substring (j, 2), 16); } //把byte数组转换成文字 v.Title = System.Text.Encoding.UTF8.GetString (bytes); byte [] bytes1 = new byte [v.Album.Length / 2]; for (int i = 0, j = 0; i < bytes1.Length; j += 2, i++) { //把16进度转换成byte bytes1 [i] = Convert.ToByte (v.Album.Substring (j, 2), 16); } //把byte数组转换成文字 v.Album = System.Text.Encoding.UTF8.GetString (bytes1); byte [] bytes2 = new byte [v.Artist.Length / 2]; for (int i = 0, j = 0; i < bytes2.Length; j += 2, i++) { //把16进度转换成byte bytes2 [i] = Convert.ToByte (v.Artist.Substring (j, 2), 16); } //把byte数组转换成文字 v.Artist = System.Text.Encoding.UTF8.GetString (bytes2); byte [] bytes3 = new byte [v.filename.Length / 2]; for (int i = 0, j = 0; i < bytes3.Length; j += 2, i++) { //把16进度转换成byte bytes3 [i] = Convert.ToByte (v.filename.Substring (j, 2), 16); } //把byte数组转换成文字 v.filename = System.Text.Encoding.UTF8.GetString (bytes3); musicInfoList.Add (new MusicInfo { SourceType = "USB", Title = v.Title, Album = v.Album, Artist = v.Artist, URL = v.filename }); } */ } catch (Exception ee) { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31Usbmusic usbmusic = new A31Usbmusic (); MainPage.MainFrameLayout.AddChidren (usbmusic); usbmusic.show (a31, musicInfoList); }); } }); }; USBrowlayout.MouseUpEventHandler += USBsource; usb.MouseUpEventHandler += USBsource; usbSD.MouseUpEventHandler += USBsource; USBhoto.MouseUpEventHandler += USBsource; #endregion #region 我的列表 var rowaddlist = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (rowaddlist); var listhoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/mylist.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; rowaddlist.AddChidren (listhoto); var addlistname = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Musiclist, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; rowaddlist.AddChidren (addlistname); var listback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; rowaddlist.AddChidren (listback); EventHandler addlist = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31MyList a31MyList = new A31MyList (); MainPage.MainFrameLayout.AddChidren (a31MyList); a31MyList.Show (); }); }); }; addlistname.MouseUpEventHandler += addlist; listback.MouseUpEventHandler += addlist; rowaddlist.MouseUpEventHandler += addlist; #endregion #region 我的最爱 var likelayout = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (likelayout); var likehoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/like.png", SelectedImagePath = "MusicIcon/likeSelected.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; likelayout.AddChidren (likehoto); var loveList = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Musiclike, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; likelayout.AddChidren (loveList); var lovenext = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), }; likelayout.AddChidren (lovenext); EventHandler lovea31Source = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31LikeList a31likeList = new A31LikeList { }; MainPage.MainFrameLayout.AddChidren (a31likeList); a31likeList.Show (a31); }); }); }; likelayout.MouseUpEventHandler += lovea31Source; loveList.MouseUpEventHandler += lovea31Source; lovenext.MouseUpEventHandler += lovea31Source; likehoto.MouseUpEventHandler += lovea31Source; #endregion #region DLNA服务器音乐 var rowlayout1 = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (rowlayout1); var dlnahoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/dlnaSource.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; rowlayout1.AddChidren (dlnahoto); var dlna = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Musicdlna, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; rowlayout1.AddChidren (dlna); var dlnaback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; rowlayout1.AddChidren (dlnaback); /* dlnaback.MouseDownEventHandler += (sen, e) => { System.Threading.Tasks.Task.Run (() => { DLNAServer dlnaServer = null; List dlnaname = new List (); try { var socket = new System.Net.Sockets.Socket (System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp); for (int i = 10000; i < 65535; i++) { try { //绑定本地端口 socket.Bind (new System.Net.IPEndPoint (System.Net.IPAddress.Any, i));//57404 break; } catch { } } string s = "M-SEARCH * HTTP/1.1\r\nMan:\"ssdp:discover\"\r\nMx:3\r\nHost:239.255.255.250:1900\r\nSt: urn:schemas-upnp-org:device:MediaServer:1\r\n\r\n"; System.Threading.Tasks.Task.Run (() => { var tempDateTime = DateTime.Now; while ((DateTime.Now - tempDateTime).TotalMilliseconds < 2000 && socket != null) { try { //请求获取dlna服务器信息 socket.SendTo (System.Text.Encoding.ASCII.GetBytes (s), System.Net.Sockets.SocketFlags.None, new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("239.255.255.250"), 1900)); System.Threading.Thread.Sleep (300); } catch { } } try { if (socket != null) { socket.Close (); socket = null; } } catch { } }); while (socket != null) { try { //接收回来的数据 var receviceBytes = new byte [1024]; System.Net.EndPoint remoteIpEndPoint = new System.Net.IPEndPoint (0, 0); //开始在这里等待接收数据, var len = socket.ReceiveFrom (receviceBytes, ref remoteIpEndPoint); var ms = new System.IO.MemoryStream (receviceBytes, 0, len); var sr = new System.IO.StreamReader (ms); string tempLine = null; string url = null; //一行一行数据判断,找出需要的信息 while ((tempLine = sr.ReadLine ()) != null) { //找出Ip地址相关的信息 if (tempLine.StartsWith ("LOCATION: http://")) { dlnaServer = new DLNAServer (); url = tempLine.Replace ("LOCATION: ", ""); dlnaServer.URL = tempLine.Replace ("LOCATION: http://", "").Split('/')[0]; } } if (url != null) { var dlnaserverlist = dlnaname.Find ((Server) => { return Server.dlnalistName == getDeviceName (url); }); if (dlnaserverlist == null) { dlnaname.Add (new MusicInfo { dlnalistName = getDeviceName (url), ID = "0", }); } } //关闭流 sr.Close (); ms.Close (); } catch { } } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31StreamingMusic a31Dlna = new A31StreamingMusic (); MainPage.MainFrameLayout.AddChidren (a31Dlna); a31Dlna.show (dlnaServer,"",dlnaname); }); } }); }; */ EventHandler selectA31dlna = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { List list = new List (); DLNAServer dlnaServer = null; try { //创建Socket System.Net.Sockets.Socket socket = new System.Net.Sockets.Socket (System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp); //绑定本地端口 //socket.Bind (new System.Net.IPEndPoint (System.Net.IPAddress.Any, 1900)); for (int i = 10000; i < 65535; i++) { try { //绑定本地端口 socket.Bind (new System.Net.IPEndPoint (System.Net.IPAddress.Any, i)); break; } catch { } } System.Net.EndPoint remoteIpEndPoint = new System.Net.IPEndPoint (0, 0); string s = "M-SEARCH * HTTP/1.1\r\nMan:\"ssdp:discover\"\r\nMx:3\r\nHost:239.255.255.250:1900\r\nSt: urn:schemas-upnp-org:device:MediaServer:1\r\n\r\n"; byte [] bytes = System.Text.Encoding.ASCII.GetBytes (s); System.Threading.Tasks.Task.Run (() => { DateTime dateTime = DateTime.Now; while (socket != null) { if (3000 < (DateTime.Now - dateTime).TotalMilliseconds) { break; } socket.SendTo (bytes, System.Net.Sockets.SocketFlags.None, new System.Net.IPEndPoint (System.Net.IPAddress.Parse ("239.255.255.250"), 1900)); System.Threading.Thread.Sleep (500); } if (socket != null) { socket.Close (); socket = null; } }); //接收回来的数据 byte [] receviceBytes = new byte [1024]; //开始在这里等待接收数据, var len = socket.ReceiveFrom (receviceBytes, ref remoteIpEndPoint); //接收到数据后就关闭Socket socket.Close (); socket = null; var dd = System.Text.Encoding.UTF8.GetString (receviceBytes); if (len != 0) { var ms = new System.IO.MemoryStream (receviceBytes, 0, len); var sr = new System.IO.StreamReader (ms); string url = null; string tempLine = null; //一行一行数据判断,找出需要的信息 while ((tempLine = sr.ReadLine ()) != null) { //找出Ip地址相关的信息 if (tempLine.StartsWith ("LOCATION: http://")) { dlnaServer = new DLNAServer (); url = tempLine.Replace ("LOCATION: ", ""); dlnaServer.URL = tempLine.Replace ("LOCATION: http://", "").Split ('/') [0]; break; } } //关闭流 sr.Close (); ms.Close (); if (dlnaServer == null) { return; } dlnaServer.ControlURL = getCommand (url); var listResult = readDlnaList (dlnaServer, "0"); if (listResult != null) { listResult = listResult.Replace ("&", "&").Replace ("<", "<").Replace (">", ">").Replace (""", "\"").Replace ("", ""); int startIndex = listResult.IndexOf ("") + "".Length; if (startIndex < endIndex) { var xml = new XmlDocument (); xml.LoadXml (listResult.Substring (startIndex, endIndex - startIndex)); foreach (XmlNode node in xml.ChildNodes [0].ChildNodes) { MusicInfo musicInfo = new MusicInfo (); musicInfo.ID = node.Attributes ["id"].Value; foreach (XmlNode temNode in node.ChildNodes) { switch (temNode.Name) { case "dc:title": musicInfo.dlnalistName = temNode.InnerText; break; } } list.Add (musicInfo); } } } } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); if (dlnaServer == null) { new Alert (Language.StringByID (MyInternationalizationString.Musicprompt), Language.StringByID (MyInternationalizationString.Musicdevice), Language.StringByID (MyInternationalizationString.MusicOK)).Show (); return; } A31Dlna a31Dlna = new A31Dlna (); MainPage.MainFrameLayout.AddChidren (a31Dlna); a31Dlna.show (dlnaServer, list); }); } }); }; dlnahoto.MouseUpEventHandler += selectA31dlna; dlna.MouseUpEventHandler += selectA31dlna; dlnaback.MouseUpEventHandler += selectA31dlna; rowlayout1.MouseUpEventHandler += selectA31dlna; #endregion #region 在线电台 var RowCn = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (RowCn); var cn = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/local.png", SelectedImagePath = "MusicIcon/localselected.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; RowCn.AddChidren (cn); var cnR = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.cnRadio, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; RowCn.AddChidren (cnR); var cnback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; RowCn.AddChidren (cnback); EventHandler CNresources = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { var radioList = readRadioList ("http://opml.radiotime.com/Browse.ashx?partnerId=yvcOjvJP"); Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31CNRadio cnRadio = new A31CNRadio (); MainPage.MainFrameLayout.AddChidren (cnRadio); cnRadio.show (a31, radioList); }); }); }; cn.MouseUpEventHandler += CNresources; cnR.MouseUpEventHandler += CNresources; cnback.MouseUpEventHandler += CNresources; RowCn.MouseUpEventHandler += CNresources; #endregion #region vTuner var vtunerrow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; //middle.AddChidren (vtunerrow); var vthhoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/bluetooth.png", SelectedImagePath = "MusicIcon/bluetoothselected.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; vtunerrow.AddChidren (vthhoto); var vtuner = new Button { Height = Application.GetRealHeight (100), //TextID = MyInternationalizationString.Musicbluetooth, Text = "vTuner", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), }; vtunerrow.AddChidren (vtuner); var nextvtuner = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; vtunerrow.AddChidren (nextvtuner); EventHandler Vresources = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); a31.vTunerList = new List (); System.Threading.Tasks.Task.Run (() => { try { var vTunerdata = readRadioList ("http://iriver.vtuner.com/setupapp/iriver/asp/browsexml/loginXML.asp?mac=a45f7477eb353cc7108b0b25da30fca3&dlang=eng"); if (vTunerdata == null) { vTunerdata = readRadioList ("http://iriver.vtuner.com/setupapp/iriver/asp/browsexml/loginXML.asp?mac=a45f7477eb353cc7108b0b25da30fca3&dlang=eng"); } var se = SecurityElement.FromString (vTunerdata); foreach (SecurityElement item in se.Children) { if (item.Tag == "Item") { a31.vTunerList.Add (new MusicInfo { Title = item.SearchForTextOfTag ("Title"), URL = item.SearchForTextOfTag ("UrlDir"), Cntype = item.SearchForTextOfTag ("ItemType") }); } } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31vTuner a31vtuner = new A31vTuner (); MainPage.MainFrameLayout.AddChidren (a31vtuner); a31vtuner.Show (a31, vtuner.Text); }); } }); }; vthhoto.MouseUpEventHandler += Vresources; vtuner.MouseUpEventHandler += Vresources; nextvtuner.MouseUpEventHandler += Vresources; vtunerrow.MouseUpEventHandler += Vresources; #endregion #region Pandora潘多拉 var pandoraRow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (pandoraRow); var p = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/pandora.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; pandoraRow.AddChidren (p); var pandora = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Pandora, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; pandoraRow.AddChidren (pandora); var pandoraback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; pandoraRow.AddChidren (pandoraback); EventHandler pandorasources = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31Pandora a31pandora = new A31Pandora (); MainPage.MainFrameLayout.AddChidren (a31pandora); a31pandora.show (a31); }); }); }; pandora.MouseUpEventHandler += pandorasources; pandoraback.MouseUpEventHandler += pandorasources; p.MouseUpEventHandler += pandorasources; pandoraRow.MouseUpEventHandler += pandorasources; #endregion #region Spotify { EventHandler myEvent = (sender, e) => { string str = "com.spotify.music"; if (Shared.Application.DeviceType == Device.Ios) { str = "spotify:"; } CommonClass.OpenApp (str); }; var Spotifylayout = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (Spotifylayout); var Spotifyhoto = new Button { Width = Application.GetMinRealAverage (61), Height = Application.GetMinRealAverage (81), UnSelectedImagePath = "MusicIcon/Spotify.png", SelectedImagePath = "MusicIcon/Spotifyselected.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; Spotifylayout.AddChidren (Spotifyhoto); var Spotify = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Spotify, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; Spotifylayout.AddChidren (Spotify); var Spotifyback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; Spotifylayout.AddChidren (Spotifyback); Spotifyhoto.MouseUpEventHandler += myEvent; Spotify.MouseUpEventHandler += myEvent; Spotifyback.MouseUpEventHandler += myEvent; Spotify.MouseUpEventHandler += myEvent; } #endregion #region QQ音乐 { EventHandler myEvent = (sender, e) => { // if (Application.DeviceType == Device.Android) //{ // com.hdl.on.CommonClass.OpenApp("com.tencent.qqmusic"); //} //else if (Application.DeviceType == Device.Ios) //{ // ON.Ios.CommonClass.OpenApp ("qqmusic://"); //} string str = "com.tencent.qqmusic"; if (Shared.Application.DeviceType == Device.Ios) { str = "qqmusic:"; } CommonClass.OpenApp (str); }; var qqmusiclayout = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (qqmusiclayout); var qqmusichoto = new Button { Width = Application.GetMinRealAverage (61), Height = Application.GetMinRealAverage (81), UnSelectedImagePath = "MusicIcon/qqmusic.png", SelectedImagePath = "MusicIcon/qqmusicselected.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; qqmusiclayout.AddChidren (qqmusichoto); var qqmusic = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.qqmusic, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; qqmusiclayout.AddChidren (qqmusic); var qqmusicback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; qqmusiclayout.AddChidren (qqmusicback); qqmusichoto.MouseUpEventHandler += myEvent; qqmusic.MouseUpEventHandler += myEvent; qqmusicback.MouseUpEventHandler += myEvent; qqmusiclayout.MouseUpEventHandler += myEvent; } #endregion #region ...广播电台Radio var airablerow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; //middle.AddChidren (airablerow); var airablehoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/Rradio.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; airablerow.AddChidren (airablehoto); var radio = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.radio, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; airablerow.AddChidren (radio); var airableback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; airablerow.AddChidren (airableback); EventHandler comclick = (sender, e) => { Tidal.ReadPlayList ("airable/radios", () => { Application.RunOnMainThread (() => { RemoveFromParent (); A31TidalLogin a31TidalLogin = new A31TidalLogin (); MainPage.MainFrameLayout.AddChidren (a31TidalLogin); a31TidalLogin.Show (A31MusicModel.Current); }); }, (path) => { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); A31PlayListPage a31PlayListPage = new A31PlayListPage (); MainPage.MainFrameLayout.AddChidren (a31PlayListPage); a31PlayListPage.Show (path, "Radios"); }); }); //MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); //System.Threading.Tasks.Task.Run (() => { // Application.RunOnMainThread (() => { // MainPage.Loading.Hide (); // A31CommonLogin a31CommonLogin = new A31CommonLogin (); // MainPage.MainFrameLayout.AddChidren (a31CommonLogin); // a31CommonLogin.show (a31, "http://meta.airable.io/view/airable/radios", radio.Text); // }); //}); }; airableback.MouseUpEventHandler += comclick; radio.MouseUpEventHandler += comclick; airablehoto.MouseUpEventHandler += comclick; airablerow.MouseUpEventHandler += comclick; #endregion #region ...播客 var podcastrow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; // middle.AddChidren (podcastrow); var podcasthoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/podcast.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; podcastrow.AddChidren (podcasthoto); var podcast = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.podcast, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, }; podcastrow.AddChidren (podcast); var podcastback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; podcastrow.AddChidren (podcastback); EventHandler podcastclick = (sender, e) => { A31CommonLogin a31CommonLogin = new A31CommonLogin (); MainPage.MainFrameLayout.AddChidren (a31CommonLogin); a31CommonLogin.show (a31, "http://meta.airable.io/view/airable/feeds", podcast.Text); }; podcastback.MouseUpEventHandler += podcastclick; podcast.MouseUpEventHandler += podcastclick; podcasthoto.MouseUpEventHandler += podcastclick; podcastrow.MouseUpEventHandler += podcastclick; #endregion #region ...Palco MP3 var Palcorow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; //middle.AddChidren (Palcorow); var Palcothoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/PalcoMP3.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; Palcorow.AddChidren (Palcothoto); var Palco = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Palco, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, }; Palcorow.AddChidren (Palco); var Palcoback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; Palcorow.AddChidren (Palcoback); EventHandler Palcoclick = (sender, e) => { A31CommonLogin a31CommonLogin = new A31CommonLogin (); MainPage.MainFrameLayout.AddChidren (a31CommonLogin); a31CommonLogin.show (a31, "http://meta.airable.io/view/palco", Palco.Text); }; Palcoback.MouseUpEventHandler += Palcoclick; Palco.MouseUpEventHandler += Palcoclick; Palcothoto.MouseUpEventHandler += Palcoclick; Palcorow.MouseUpEventHandler += Palcoclick; #endregion #region ...TIDAL var tidalrow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (tidalrow); var tidalhoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/Tidal.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; tidalrow.AddChidren (tidalhoto); var tidal = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.tidal, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; tidalrow.AddChidren (tidal); var tidalback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; tidalrow.AddChidren (tidalback); EventHandler tidalclick = (sender, e) => { //如果还没有获取到Token或者还没有登录,提示用户登录 if (Tidal.CurrentTidal == null || !Tidal.CurrentTidal.IsLogin) { var tidalLogin = new A31TidalLogin (); MainPage.MainFrameLayout.AddChidren (tidalLogin); tidalLogin.Show (a31); } else { var a31TidalHomePage = new A31TidalHomePage (); MainPage.MainFrameLayout.AddChidren (a31TidalHomePage); a31TidalHomePage.Show (); } }; tidalhoto.MouseUpEventHandler += tidalclick; tidal.MouseUpEventHandler += tidalclick; tidalback.MouseUpEventHandler += tidalclick; tidalrow.MouseUpEventHandler += tidalclick; #endregion #region 蓝牙 var bluetoothrowlayout = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; //支持蓝牙功能 if (a31.A31DeviceType == 918||a31.A31DeviceType == 919 || a31.A31DeviceType == 920) { middle.AddChidren (bluetoothrowlayout); } var bluetoothhoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/bluetooth.png", SelectedImagePath = "MusicIcon/bluetoothselected.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; bluetoothrowlayout.AddChidren (bluetoothhoto); var bluetooth = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Musicbluetooth, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; bluetoothrowlayout.AddChidren (bluetooth); var nextbluetooth = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; bluetoothrowlayout.AddChidren (nextbluetooth); EventHandler bluetoothsources = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { sendCommand ("bluetooth"); Application.RunOnMainThread (() => { MainPage.Loading.Hide (); MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1); MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1); A31PlayMusicPage a31PlayMusicPage = new A31PlayMusicPage (); MainPage.MainFrameLayout.AddChidren (a31PlayMusicPage); a31PlayMusicPage.Show (new List ()); }); }); }; bluetoothrowlayout.MouseUpEventHandler += bluetoothsources; bluetoothhoto.MouseUpEventHandler += bluetoothsources; bluetooth.MouseUpEventHandler += bluetoothsources; nextbluetooth.MouseUpEventHandler += bluetoothsources; #endregion #region 线路输入 var linerowlayout = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (linerowlayout); var linehoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/muiscline.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; linerowlayout.AddChidren (linehoto); var line = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.linein, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), TextColor = SkinStyle.Current.MusicTextColor, }; linerowlayout.AddChidren (line); var nextline = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; linerowlayout.AddChidren (nextline); EventHandler linesources = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); System.Threading.Tasks.Task.Run (() => { sendCommand ("line-in"); Application.RunOnMainThread (() => { MainPage.Loading.Hide (); MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1); MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1); A31PlayMusicPage a31PlayMusicPage = new A31PlayMusicPage (); MainPage.MainFrameLayout.AddChidren (a31PlayMusicPage); a31PlayMusicPage.Show (new List ()); }); }); }; linerowlayout.MouseUpEventHandler += linesources; linehoto.MouseUpEventHandler += linesources; line.MouseUpEventHandler += linesources; nextline.MouseUpEventHandler += linesources; #endregion #region 我的设置 var mystelayout = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (mystelayout); var sethoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/set.png", SelectedImagePath = "MusicIcon/setSelected.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical }; mystelayout.AddChidren (sethoto); var set = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Musicset, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; mystelayout.AddChidren (set); var setback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (550), Gravity = Gravity.CenterVertical, }; mystelayout.AddChidren (setback); EventHandler setsources = (sender, e) => { MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load));
 System.Threading.Tasks.Task.Run (() => {
 Application.RunOnMainThread (() => {
 MainPage.Loading.Hide ();
 var setUpPage = new SetUpPage ();
 MainPage.MainFrameLayout.AddChidren (setUpPage);
 setUpPage.Show (a31);
 });
 });
 }; sethoto.MouseUpEventHandler += setsources; set.MouseUpEventHandler += setsources; setback.MouseUpEventHandler += setsources; mystelayout.MouseUpEventHandler += setsources; #endregion #region 删除当前音乐播放器 var delrow = new RowLayout { Height = Application.GetRealHeight (100), LineColor = SkinStyle.Current.MusicRowLayoutLineColor, }; middle.AddChidren (delrow); var delhoto = new Button { Width = Application.GetRealWidth (61), Height = Application.GetRealHeight (81), UnSelectedImagePath = "MusicIcon/delplayer.png", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, }; delrow.AddChidren (delhoto); var delplayer = new Button { Height = Application.GetRealHeight (100), TextID = MyInternationalizationString.Deletemusicplayer, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (130), Gravity = Gravity.CenterVertical, TextColor = SkinStyle.Current.MusicTextColor, }; delrow.AddChidren (delplayer); EventHandler delmusicplayer = (sender, e) => { var alert = new Alert (Language.StringByID (MyInternationalizationString.prompt), Language.StringByID (MyInternationalizationString.Deletemusicplayer), Language.StringByID (MyInternationalizationString.cancel), Language.StringByID (MyInternationalizationString.confirm)); alert.ResultEventHandler += (sender1, e1) => { if (e1) { A31MusicModel.A31MusicModelList.Remove (a31); A31MusicModel.Save (); MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 3); MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 2); RemoveFromParent (); MyMusic mymusic = new MyMusic (); MainPage.MainFrameLayout.AddChidren (mymusic); mymusic.Show (true); } else { } }; alert.Show (); }; delrow.MouseUpEventHandler += delmusicplayer; delhoto.MouseUpEventHandler += delmusicplayer; delplayer.MouseUpEventHandler += delmusicplayer; #endregion } /// /// 读取歌曲信息 /// /// /// string usbserarchSong (string id) { Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); try { byte [] recevieBytes = webClient.DownloadData (new Uri ("http://" + id + "/httpapi.asp?command=getFileInfo" + ":" + 0 + ":" + 1000)); return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length); } catch { return ""; } } /// /// 读取DLNA的音乐列表 /// /// 列表ID /// 读取到的音乐列表信息,读取不到反馈为null string readDlnaList (DLNAServer dlnaServer, string id) { string tempString = "" + id + "BrowseDirectChildren*0999+dc:title"; 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-upnp-org:service:ContentDirectory:1#Browse\""); try { byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + dlnaServer.URL + dlnaServer.ControlURL), "POST", System.Text.Encoding.UTF8.GetBytes (tempString)); return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length); } catch (Exception e) { return null; } } string getCommand (string url) { Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); try { var ddd = SecurityElement.FromString (webClient.DownloadString (url)).SearchForChildByTag ("device").SearchForChildByTag ("serviceList"); foreach (SecurityElement se in ddd.Children) { if (se.SearchForTextOfTag ("serviceType").Contains ("urn:schemas-upnp-org:service:ContentDirectory")) { return se.SearchForTextOfTag ("controlURL"); } } } catch (Exception e) { } return "/ContentDirectory/Control"; } /// /// 读取电台组列表 /// /// 读取到的电台组列表信息,读取不到反馈为null string readRadioList (string url) { Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (10000); webClient.Proxy = null; webClient.Headers.Add ("Content-type", "plain/text; charset=UTF-8"); //System.Console.WriteLine("===========" + Language.CurrentLanguage); if (Language.CurrentLanguage == "Chinese") { webClient.Headers.Add ("Accept-Language", "zh-cn"); } else { webClient.Headers.Add ("Accept-Language", "en-us"); } try { byte [] recevieBytes = webClient.DownloadData (new Uri (url)); return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length); } catch (Exception e) { return null; } } void sendCommand (string coutn) { System.Threading.Tasks.Task.Run (() => { Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); try { byte [] recevieBytes1 = webClient.DownloadData (new Uri ("http://" + a31MusicModel.IPAddress + "/httpapi.asp?command=setPlayerCmd:switchmode:" + coutn)); } catch (Exception ex) { //string ee = ex.Message; } }); } /// /// 获取当前播放的列表 /// string getUSBPlayList () { StringBuilder getPlayList = new StringBuilder (); getPlayList.AppendLine (""); getPlayList.AppendLine (""); getPlayList.AppendLine (""); getPlayList.AppendLine ("USBDiskQueue"); 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#BrowseQueue\""); webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); try { byte [] recevieBytes = webClient.UploadData (new Uri ("http://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (getPlayList.ToString ())); return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length); } catch { } return null; } static string userName = "ieast"; static string password = "60b25158ee94"; public static Airable ReadRadiohome (string url) { System.IO.StringReader sr = null; Airable airable = null; try { Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\""); webClient.Headers.Add ("Authorization", "Basic " + Convert.ToBase64String (Encoding.ASCII.GetBytes (userName + ":" + password))); byte [] recevieBytes = webClient.DownloadData (new Uri (url)); var ddd = Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length); sr = new System.IO.StringReader (Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length)); string line = null; StringBuilder stringBuilder = null; while ((line = sr.ReadLine ()) != null) { line = line.Trim (); if (stringBuilder == null) { if (line.EndsWith ("
") && sr.ReadLine ().Trim () == "{") { stringBuilder = new StringBuilder (); stringBuilder.AppendLine ("{"); } } else { if (line.EndsWith ("")) { stringBuilder.AppendLine ("}"); string s = @stringBuilder.ToString ().Replace (",}", "}").Replace ("\"content\": []", "\"content\": \"\""); airable = Newtonsoft.Json.JsonConvert.DeserializeObject (@s); break; } else { if (line.Contains ("")) { line = line.Remove (line.IndexOf ("") - line.IndexOf ("", ""); } stringBuilder.AppendLine (@line); } } } } catch { } finally { if (sr != null) sr.Close (); } return airable; } /// /// 获取dlna的名称 /// /// /// /// string getDeviceName (string url) { string deviceName = null; System.IO.StreamReader sr = null; Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (); try { var receviceBytes = webClient.DownloadData (new Uri (url)); sr = new System.IO.StreamReader (new System.IO.MemoryStream (receviceBytes), Encoding.UTF8); string line = null; string deviceType = null; while ((line = sr.ReadLine ().Trim ()) != null) { //System.Console.WriteLine (line); if (line.StartsWith ("")) { deviceName = line.Replace ("", "").Replace ("", ""); } } } catch { } finally { if (sr != null) { sr.Close (); } } return deviceName; } } }