using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using Shared.SimpleControl;
|
using Shared.SimpleControl.Pad;
|
using System.Xml;
|
using Shared.SimpleControl.R;
|
|
namespace Shared.SimpleControl.Pad.Music
|
{
|
/// <summary>
|
/// 当前播放列表
|
/// </summary>
|
class A31PlayList : FrameLayout
|
{
|
VerticalScrolViewLayout verticalScrolViewLayout;
|
public Button btnListName;
|
|
public void InitFace (FrameLayout MusicSourcePage)
|
{
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (100),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
this.AddChidren (topFrameLayout);
|
|
btnListName = new Button {
|
TextID = MyInternationalizationString.Musicplaylist,
|
};
|
topFrameLayout.AddChidren (btnListName);
|
|
var back = new Button {
|
Width = Application.GetRealWidth (72),
|
Height = Application.GetRealHeight (89),
|
X = Application.GetRealWidth (-1),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/PlayBack.png",
|
};
|
back.MouseDownEventHandler += (sender, e) => {
|
RemoveFromParent ();
|
};
|
topFrameLayout.AddChidren (back);
|
|
FrameLayout fram = new FrameLayout {
|
Height = Application.GetRealHeight (1536 - 100-150),
|
Y = topFrameLayout.Bottom,
|
BackgroundColor = 0xff2F2F2F,
|
};
|
AddChidren (fram);
|
verticalScrolViewLayout = new VerticalScrolViewLayout {
|
};
|
fram.AddChidren (verticalScrolViewLayout);
|
}
|
|
public override void RemoveFromParent ()
|
{
|
if (updateThread != null && updateThread.IsAlive) {
|
updateThread.Abort ();
|
updateThread = null;
|
}
|
if (downLoadImageThread != null && downLoadImageThread.IsAlive) {
|
downLoadImageThread.Abort ();
|
downLoadImageThread = null;
|
}
|
base.RemoveFromParent ();
|
}
|
|
void resetSongColor ()
|
{
|
sleepDateTime = DateTime.Now;
|
for (int i = 0; i < verticalScrolViewLayout.ChildrenCount; i++) {
|
var view = (RowLayout)verticalScrolViewLayout.GetChildren (i);
|
var songName = (Button)view.GetChildren (1);
|
songName.TextColor = 0xffffffff;
|
}
|
}
|
|
public void Musiclist (string listName, string playSource,FrameLayout MusicSourcePage)
|
{
|
btnListName.Text = Language.StringByID (MyInternationalizationString.Musicplaylist);
|
|
List<Button> buttonList = new List<Button> (100);
|
|
for (int i = 0; i < A31MusicModel.Current.CurrentPlayMusicInfoList.Count; i++)
|
{
|
var musicInfo = A31MusicModel.Current.CurrentPlayMusicInfoList [i];
|
|
|
var rowSong = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
};
|
verticalScrolViewLayout.AddChidren (rowSong);
|
|
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",
|
};
|
rowSong.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 songBtn = new Button {
|
Width = Application.GetRealWidth (400),
|
Text = musicInfo.Title,
|
Height = Application.GetRealHeight (50),
|
TextAlignment = TextAlignment.BottomLeft,
|
X = Application.GetRealWidth (100),
|
Tag = musicInfo,
|
};
|
rowSong.AddChidren (songBtn);
|
|
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 = songBtn.Bottom,
|
Tag = musicInfo,
|
TextColor = 0x75ffffff,
|
|
};
|
rowSong.AddChidren (artist);
|
|
EventHandler<MouseEventArgs> musics = (sender, e) => {
|
resetSongColor ();
|
rowSong.BackgroundColor = 0xffFE5E00;
|
A31MusicModel.Current.A31PlayStatus.Title = songBtn.Text;
|
System.Threading.Tasks.Task.Run (() => {
|
//pushList (songBtn.Tag as MusicInfo, listName, playSource);
|
listplay (listName, songBtn.Tag as MusicInfo);
|
});
|
System.Threading.Tasks.Task.Run (() => {
|
System.Threading.Thread.Sleep (100);
|
Application.RunOnMainThread (() => {
|
songBtn.TextColor = 0xffFE5E00;
|
rowSong.BackgroundColor = 0x00000000;
|
});
|
});
|
};
|
songBtn.MouseUpEventHandler += musics;
|
artist.MouseUpEventHandler += musics;
|
title.MouseUpEventHandler += musics;
|
|
var del = new Button {
|
TextID = MyInternationalizationString.Musicdel,
|
BackgroundColor = 0xFFFF0000,
|
Tag = A31MusicModel.Current.CurrentPlayMusicInfoList [i].ID,
|
};
|
//rowsong.AddRightView(del);
|
del.MouseUpEventHandler += (sender, e) => {
|
for (int j = 0; j < A31MusicModel.Current.CurrentPlayMusicInfoList.Count; j++) {
|
if (A31MusicModel.Current.CurrentPlayMusicInfoList [j].ID == del.Tag.ToString ()) {
|
A31MusicModel.Current.CurrentPlayMusicInfoList.RemoveAt (j);
|
break;
|
}
|
}
|
//这里需要更新一下要发送的列表信息
|
rowSong.RemoveFromParent ();
|
};
|
}
|
|
|
updateThread = new System.Threading.Thread (new System.Threading.ThreadStart (() => {
|
while (true) {
|
System.Threading.Thread.Sleep (500);
|
if ((DateTime.Now - sleepDateTime).TotalSeconds < 3) {
|
continue;
|
}
|
sleepDateTime = DateTime.Now;
|
Shared.Application.RunOnMainThread (() => {
|
try {
|
for (int i = 0; i < verticalScrolViewLayout.ChildrenCount; i++) {
|
var view = (RowLayout)verticalScrolViewLayout.GetChildren (i);
|
var songName = (Button)view.GetChildren (1);
|
if (A31MusicModel.Current.A31PlayStatus.Title == songName.Text) {
|
songName.TextColor = 0xffFE5E00;
|
} else {
|
songName.TextColor = 0xffffffff;
|
}
|
}
|
} catch { }
|
});
|
}
|
})) { IsBackground=true};
|
updateThread.Start ();
|
|
downLoadImageThread = new System.Threading.Thread (new System.Threading.ThreadStart (() => {
|
for (int i = 0; i < buttonList.Count; i++) {
|
try {
|
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 {
|
|
}
|
}
|
})) { IsBackground=true};
|
downLoadImageThread.Start ();
|
}
|
|
DateTime sleepDateTime = DateTime.MinValue;
|
System.Threading.Thread updateThread;
|
System.Threading.Thread downLoadImageThread;
|
|
void pushList (MusicInfo musicInfo, string listName, string sourceName)
|
{
|
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>");
|
sb.AppendLine ("<PlayList>");
|
sb.AppendLine ("<ListName>" + listName + "</ListName>");
|
sb.AppendLine ("<ListInfo>");
|
sb.AppendLine ("<SourceName>" + sourceName + "</SourceName>");
|
sb.AppendLine ("<MarkSearch>0</MarkSearch>");
|
sb.AppendLine ("<TrackNumber>" + A31MusicModel.Current.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 number = 1;
|
int i = 0;
|
foreach (var tempMusicInfo in A31MusicModel.Current.CurrentPlayMusicInfoList) {
|
|
i++;
|
if (musicInfo == tempMusicInfo) {
|
number = 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 ("<Source>" + tempMusicInfo.SourceName + "</Source>");
|
sb.AppendLine ("</Track" + i + ">");
|
|
}
|
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>" + 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 { }
|
}
|
|
void listplay (string listName, MusicInfo musicInfo)
|
{
|
StringBuilder playstrings = new StringBuilder ();
|
int number = 1;
|
int i = 0;
|
foreach (var tempMusicInfo in A31MusicModel.Current.CurrentPlayMusicInfoList) {
|
i++;
|
if (musicInfo == tempMusicInfo) {
|
number = i;
|
}
|
}
|
playstrings.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
|
playstrings.AppendLine ("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">");
|
playstrings.AppendLine ("<s:Body>");
|
playstrings.AppendLine ("<u:PlayQueueWithIndex xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
|
playstrings.AppendLine ("<QueueName>" + listName + "</QueueName>");
|
playstrings.AppendLine ("<Index>" + number + "</Index>");
|
playstrings.AppendLine ("</u:PlayQueueWithIndex>");
|
playstrings.AppendLine ("</s:Body>");
|
playstrings.AppendLine ("</s:Envelope>");
|
|
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://" + A31MusicModel.Current.IPAddress + ":" + A31MusicModel.Current.Port + "/upnp/control/PlayQueue1"), "POST", Encoding.UTF8.GetBytes (playstrings.ToString ()));
|
var s = System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
} catch { }
|
|
}
|
|
|
}
|
}
|