using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using Shared.Net;
|
using Shared.SimpleControl;
|
using Shared.SimpleControl.Phone.Music;
|
using Shared.SimpleControl.R;
|
|
namespace SmartHome
|
{
|
public class A31AddListMuisc : FrameLayout
|
{
|
|
bool isExited;
|
public void Show (string listname, List<MusicInfo> musicInfoList)
|
{
|
AddChidren (new Button {
|
Height = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
});
|
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (100),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
Y = Application.GetRealHeight (36),
|
};
|
AddChidren (topFrameLayout);
|
|
var LocallistName = new Button {
|
Text = listname,
|
TextColor=SkinStyle.Current.MusicTextColor,
|
};
|
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 ();
|
isExited = true;
|
};
|
|
var fra = new FrameLayout {
|
Y = topFrameLayout.Bottom,
|
Height = Application.GetRealHeight (Application.DesignHeight - 100 - 36),
|
BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout,
|
};
|
AddChidren (fra);
|
|
var middle = new VerticalScrolViewLayout ();
|
fra.AddChidren (middle);
|
if (musicInfoList == null) {
|
return;
|
}
|
List<Button> buttonList = new List<Button> (100);
|
for (int i = 0; i < musicInfoList.Count; i++) {
|
var musicInfo = musicInfoList [i];
|
|
var usbrowL = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
LineColor = SkinStyle.Current.MusicRowLayoutLineColor,
|
};
|
middle.AddChidren (usbrowL);
|
|
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",
|
};
|
usbrowL.AddChidren (title);
|
|
|
var path = "";
|
if (Shared.Application.IsPad) {
|
path = "Pad/" + "MusicImage/AlbumArtistImage_";
|
} else {
|
path = "Phone/" + "MusicImage/AlbumArtistImage_";
|
}
|
if (Shared.IO.FileUtils.Exists (path + musicInfo.Album)) {
|
title.UnSelectedImagePath = path + musicInfo.Album;
|
} else if (Shared.IO.FileUtils.Exists (path + musicInfo.Artist)) {
|
title.UnSelectedImagePath = path + musicInfo.Artist;
|
} else {
|
title.UnSelectedImagePath = "MusicIcon/musicplay1.png";
|
title.AddTag ("Album", musicInfo.Album);
|
title.AddTag ("Artist", musicInfo.Artist);
|
buttonList.Add (title);
|
}
|
|
var btnMusicName = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (50),
|
Text = musicInfoList [i].Title,
|
TextAlignment = TextAlignment.BottomLeft,
|
X = Application.GetRealWidth (100),
|
Tag = musicInfo,
|
TextColor=SkinStyle.Current.MusicTextColor,
|
};
|
usbrowL.AddChidren (btnMusicName);
|
|
|
var Artist = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (50),
|
Text = musicInfo.Artist + "-" + musicInfo.Album,
|
TextAlignment = TextAlignment.TopLeft,
|
X = Application.GetRealWidth (100),
|
Y = btnMusicName.Bottom,
|
Tag = musicInfo,
|
TextColor = SkinStyle.Current.MusicArtistTextColor,
|
//TextColor = 0x75ffffff,
|
};
|
usbrowL.AddChidren (Artist);
|
|
EventHandler<MouseEventArgs> musics = (sender, e) => {
|
usbrowL.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);
|
//移除当前控件界面
|
this.RemoveFromParent ();
|
MainPage.MainFrameLayout.RemoveViewByTag ("A31PlayMusicPage");
|
A31PlayMusicPage a31PlayMusicPage = new A31PlayMusicPage ();
|
MainPage.MainFrameLayout.AddChidren (a31PlayMusicPage);
|
a31PlayMusicPage.Show (musicInfoList);
|
//a31PlayMusicPage.Source = "STATION-NETWORK";
|
A31MusicModel.Current.A31PlayStatus.Title = btnMusicName.Text;
|
System.Threading.Tasks.Task.Run (() => {
|
pushList (btnMusicName.Tag as MusicInfo, listname, musicInfoList);
|
//MyMusic.dateTime = System.DateTime.Now.AddSeconds (-5);
|
});
|
|
});
|
});
|
};
|
btnMusicName.MouseUpEventHandler += musics;
|
Artist.MouseUpEventHandler += musics;
|
|
var del = new Button {
|
TextID = MyInternationalizationString.Musicdel,
|
BackgroundColor = 0xFFFF0000,
|
Tag = musicInfo,
|
|
};
|
del.MouseUpEventHandler += (sender1, e1) => {
|
|
musicInfoList.Remove (del.Tag as MusicInfo);
|
usbrowL.RemoveFromParent ();
|
A31MusicModel.Save ();
|
};
|
usbrowL.AddRightView (del);
|
}
|
|
|
System.Threading.Tasks.Task.Run (() => {
|
for (int i = 0; i < buttonList.Count; i++) {
|
try {
|
if (isExited) {
|
return;
|
}
|
var button = buttonList [i];
|
var album = button.GetTagByKey ("Album");
|
var artist = button.GetTagByKey ("Artist");
|
if (album == null || artist == null) {
|
continue;
|
}
|
var filePath = Shared.IO.FileUtils.DownLoadImageFormBaidu (album.ToString (), artist.ToString ());
|
if (filePath != null) {
|
Application.RunOnMainThread (() => {
|
button.UnSelectedImagePath = filePath;
|
});
|
}
|
} catch {
|
|
}
|
}
|
});
|
|
}
|
|
|
public void pushList (MusicInfo musicInfo, string listname, List<MusicInfo> musiclist)
|
{
|
|
//最大发送的条数
|
int maxCount = 50;
|
//找出当前点击音乐的索引
|
int statIndex = musiclist.FindIndex ((obj) => { return obj == musicInfo; });
|
//点击后面还有多少条音乐
|
int count = musiclist.Count - statIndex;
|
int endIndex = 0;
|
if (maxCount < count) {
|
//如果后面的音乐大于最大数,设置后面数据的最大索引
|
endIndex = statIndex + maxCount - 1;
|
} else {
|
//如果后面数据不多,就用总数减去最大条数,得到开始索引
|
statIndex = musiclist.Count - maxCount - 1;
|
endIndex = musiclist.Count - 1;
|
}
|
//如果开始索引小于0,那就设置为第一条音乐
|
if (statIndex < 0) {
|
statIndex = 0;
|
}
|
|
StringBuilder sb = new StringBuilder ();
|
sb.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
sb.AppendLine ("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
|
sb.AppendLine ("<s:Body>");
|
sb.AppendLine ("<u:CreateQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
|
sb.AppendLine ("<QueueContext><?xml version=\"1.0\"?>");
|
sb.AppendLine ("<PlayList>");
|
sb.AppendLine ("<ListName>DLNA" + listname + "</ListName>");
|
sb.AppendLine ("<ListInfo>");
|
sb.AppendLine ("<Radio>0</Radio>");//
|
sb.AppendLine ("<SourceName>UPnPServer</SourceName>");//
|
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 number = 1;
|
|
for (int i = statIndex, Tracknumber = 1; i <= endIndex; i++, Tracknumber++) {
|
var tempMusicInfo = musiclist [i];
|
|
if (musicInfo == tempMusicInfo) {
|
number = 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;" + 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;" + "0:0:0.0" + "&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>STATION-NETWORK</Source>");//UPnPServer
|
sb.AppendLine ("<Key>" + tempMusicInfo.URL + "</Key>");
|
sb.AppendLine ("</Track" + Tracknumber + ">");
|
}
|
sb.AppendLine ("</Tracks>");
|
sb.AppendLine ("</PlayList>");
|
sb.AppendLine ("</QueueContext>");
|
sb.AppendLine ("</u:CreateQueue>");
|
sb.AppendLine ("</s:Body>");
|
sb.AppendLine ("</s:Envelope>");
|
|
sendMusicLists (A31MusicModel.Current.IPAddress, A31MusicModel.Current.Port, "CreateQueue", sb.ToString ());
|
|
StringBuilder playString = new StringBuilder ();
|
playString.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
playString.AppendLine ("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
|
playString.AppendLine ("<s:Body>");
|
playString.AppendLine ("<u:PlayQueueWithIndex xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
|
playString.AppendLine ("<QueueName>DLNA" + listname + "</QueueName>");
|
playString.AppendLine ("<Index>" + number + "</Index>");
|
playString.AppendLine ("</u:PlayQueueWithIndex>");
|
playString.AppendLine ("</s:Body>");
|
playString.AppendLine ("</s:Envelope>");
|
|
play (A31MusicModel.Current.IPAddress, A31MusicModel.Current.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 {
|
|
}
|
}
|
}
|
}
|