using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using System.Xml;
|
using Shared.SimpleControl.R;
|
using SmartHome;
|
|
namespace Shared.SimpleControl.Phone.Music
|
{
|
class A31DlnaList : FrameLayout
|
{
|
public void show (DLNAServer dlnaServer, string ListName, List<MusicInfo> list)
|
{
|
|
this.AddChidren (new Button {
|
Height = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
});
|
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (100),
|
Y = Application.GetRealHeight (30),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
};
|
this.AddChidren (topFrameLayout);
|
|
var dlnalistName = new Button {
|
Text = ListName,
|
TextColor=SkinStyle.Current.MusicTextColor,
|
|
};
|
topFrameLayout.AddChidren (dlnalistName);
|
|
|
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 ();
|
};
|
|
|
VerticalScrolViewLayout middle = new VerticalScrolViewLayout ();
|
middle.Y = topFrameLayout.Bottom;
|
middle.Height = Application.GetRealHeight (Application.DesignHeight - 136);
|
//middle.BackgroundColor = 0xff2F2F2F;
|
middle.BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout;
|
AddChidren (middle);
|
|
for (int i = 0; i < list.Count; i++) {
|
var music = list [i];
|
|
var dlnarowLayout = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
LineColor = SkinStyle.Current.MusicRowLayoutLineColor,
|
};
|
middle.AddChidren (dlnarowLayout);
|
|
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,
|
};
|
dlnarowLayout.AddChidren (radius);
|
|
|
var listnext = new Button {
|
Width = Application.GetRealWidth (87),
|
Height = Application.GetRealHeight (100),
|
UnSelectedImagePath = "MusicIcon/Next.png",
|
X = Application.GetRealWidth (550),
|
};
|
dlnarowLayout.AddChidren (listnext);
|
|
var dlnalists = new Button {
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (80),
|
Text = music.dlnalistName,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
|
};
|
|
dlnarowLayout.AddChidren (dlnalists);
|
|
EventHandler<MouseEventArgs> A31dlnaserver = (sender, e) => {
|
MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load));
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
var dlnaString = dlnalistsong (dlnaServer, music.ID);
|
if (dlnaString == null) {
|
return;
|
}
|
list.Clear ();
|
dlnaString = dlnaString.Replace ("&", "&").Replace ("<", "<").Replace (">", ">").Replace (""", "\"").Replace ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "").Replace ("&", "");
|
|
int StartIndex = dlnaString.IndexOf ("<DIDL-Lite");
|
int endIndex = dlnaString.IndexOf ("</DIDL-Lite>") + "</DIDL-Lite>".Length;
|
if (endIndex <= StartIndex) {
|
return;
|
}
|
var xml = new XmlDocument ();
|
|
xml.LoadXml (dlnaString.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 "upnp:class":
|
musicInfo.IsDirectory = temnode.InnerText != "object.item.audioItem.musicTrack";
|
break;
|
case "upnp:album":
|
musicInfo.Album = temnode.InnerText;
|
break;
|
|
case "dc:title":
|
musicInfo.Title = temnode.InnerText;
|
break;
|
|
case "upnp:artist":
|
musicInfo.Artist = temnode.InnerText;
|
break;
|
case "upnp:albumArtURI":
|
//musicInfo.Image = temnode.InnerText;
|
#region 初始化网络图片路径
|
string path = "";
|
if (Shared.Application.IsPad) {
|
path = "Pad/" + "MusicImage/";
|
} else {
|
path = "Phone/" + "MusicImage/";
|
}
|
path = System.IO.Path.Combine (Shared.IO.FileUtils.RootPath, path + temnode.InnerText.Replace ('/', '_').Replace ('\\', '_').Replace (':', '_').Replace ('*', '_').Replace ('?', '_').Replace ('"', '_').Replace ('<', '_').Replace ('>', '_').Replace ('|', '_'));
|
musicInfo.Image = path;
|
#endregion
|
Shared.IO.FileUtils.DownLoadImage (musicInfo.Image, temnode.InnerText);
|
break;
|
case "res":
|
musicInfo.URL = temnode.InnerText;
|
var duration = temnode.Attributes ["duration"];
|
if (duration != null) {
|
musicInfo.Duration = duration.Value;
|
}
|
break;
|
}
|
}
|
list.Add (musicInfo);
|
}
|
} catch { } finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
A31DlnaListMusic a31DlnaListMusic = new A31DlnaListMusic ();
|
MainPage.MainFrameLayout.AddChidren (a31DlnaListMusic);
|
a31DlnaListMusic.show (dlnaServer, music.dlnalistName, list);
|
});
|
}
|
});
|
};
|
dlnalists.MouseUpEventHandler += A31dlnaserver;
|
listnext.MouseUpEventHandler += A31dlnaserver;
|
|
}
|
}
|
|
string dlnalistsong (DLNAServer dlnaServer, string id)
|
{
|
string aa = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Body><u:Browse xmlns:u=\"urn:schemas-upnp-org:service:ContentDirectory:1\"><ObjectID>" + id + "</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><Filter>*</Filter><StartingIndex>0</StartingIndex><RequestedCount>999</RequestedCount><SortCriteria>+dc:title</SortCriteria></u:Browse></s:Body></s:Envelope>";
|
|
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 (aa));
|
return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
} catch (Exception e) {
|
string s = e.Message;
|
}
|
return null;
|
|
}
|
}
|
}
|