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.SimpleControl;
namespace SmartHome.UI.SimpleControl.Phone.Music
{
class A31SoAaAl : FrameLayout
{
///
/// 列表名
///
Button listName;
public void Show(A31MusicModel a31, int a, string Listname)
{
AddChidren(new Button
{
Height = Application.GetRealHeight(30),
BackgroundColor = SkinStyle.Current.MainColor,
});
var topFrameLayout = new FrameLayout
{
Height = Application.GetRealHeight(100),
Y = Application.GetRealHeight(30),
BackgroundColor = SkinStyle.Current.MainColor,
};
AddChidren(topFrameLayout);
listName = new Button
{
TextID = MyInternationalizationString.LocalMusic,
TextSize = 18,
};
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.MouseDownEventHandler += (sender, e) =>
{
RemoveFromParent();
};
var middle = new VerticalScrolViewLayout();
middle.Y = topFrameLayout.Bottom;
middle.Height = Application.GetRealHeight (Application.DesignHeight - 130);
middle.BackgroundColor = 0xff2F2F2F;
AddChidren(middle);
#region 歌曲
if (a == 1)
{
listName.Text = Language.StringByID(MyInternationalizationString.LocalMusic);
int number = 0;
foreach (var Musicsong in MusicInfo.MusicInfoList)
{
number++;
var rowsong = new RowLayout
{
Height = Application.GetRealHeight(100),
};
middle.AddChidren(rowsong);
var title = new Button
{
Width = Application.GetRealWidth(80),
Height = Application.GetRealHeight(70),
X = Application.GetRealWidth(10),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayMusic.png",
};
rowsong.AddChidren(title);
var btnplayMusic = new Button
{
Height = Application.GetRealHeight(100),
TextAlignment = TextAlignment.CenterLeft,
X = Application.GetRealWidth(120),
Gravity = Gravity.CenterVertical,
Text = Musicsong.Title,
Tag = number,
};
rowsong.AddChidren(btnplayMusic);
btnplayMusic.MouseUpEventHandler += (sender, e) =>
{
rowsong.BackgroundColor = 0xffFE5E00;
System.Threading.Tasks.Task.Run(() =>
{
System.Threading.Thread.Sleep(100);
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();
A31PlayMusicPage a31PlayMusic = new A31PlayMusicPage();
MainPage.MainFrameLayout.AddChidren(a31PlayMusic);
a31PlayMusic.Show( MusicInfo.MusicInfoList);
// a31PlayMusic.Source = "wifi";
pushList(a31, btnplayMusic.Tag, Language.StringByID(MyInternationalizationString.LocalMusic));
});
});
};
}
}
#endregion
#region 歌手
if (a == 2)
{
listName.Text = Language.StringByID(MyInternationalizationString.Musicartist);
var artistList = new List();
foreach (var music in MusicInfo.MusicInfoList)
{
if (!artistList.Contains(music.Artist))
{
artistList.Add(music.Artist);
}
}
foreach (var artist in artistList)
{
var rowartist = new RowLayout
{
Height = Application.GetRealHeight(100),
};
middle.AddChidren(rowartist);
var btnartist = new Button
{
Height = Application.GetRealHeight(100),
X = Application.GetRealWidth(20),
TextAlignment = TextAlignment.CenterLeft,
Text = artist,
};
rowartist.AddChidren(btnartist);
var musicInfo = new List();
for (int j = 0; j < MusicInfo.MusicInfoList.Count; j++)
{
if (MusicInfo.MusicInfoList[j].Artist == btnartist.Text.ToString())
{
musicInfo.Add(MusicInfo.MusicInfoList[j]);
}
}
btnartist.MouseUpEventHandler += (sender1, e1) =>
{
A31MusicSoAaAl a31MusicSoAaAl = new A31MusicSoAaAl();
MainPage.MainFrameLayout.AddChidren(a31MusicSoAaAl);
a31MusicSoAaAl.Show(a31, artist, musicInfo);
};
}
}
#endregion
#region 专辑
if (a == 3)
{
listName.Text = Language.StringByID(MyInternationalizationString.Musicalbum);
var albumList = new List();
foreach (var musicalbum in MusicInfo.MusicInfoList)
{
if (!albumList.Contains(musicalbum.Album))
{
albumList.Add(musicalbum.Album);
}
}
foreach (var album in albumList)
{
var rowalbum = new RowLayout
{
Height = Application.GetRealHeight(100),
};
middle.AddChidren(rowalbum);
var btnalbumName = new Button
{
Height = Application.GetRealHeight(100),
Text = album,
X = Application.GetRealWidth(20),
TextAlignment = TextAlignment.CenterLeft,
};
rowalbum.AddChidren(btnalbumName);
var albumMusiclist = new List();
for (int i = 0; i < MusicInfo.MusicInfoList.Count; i++)
{
if (MusicInfo.MusicInfoList[i].Album == btnalbumName.Text.ToString())
{
albumMusiclist.Add(MusicInfo.MusicInfoList[i]);
}
}
btnalbumName.MouseUpEventHandler += (sender, e) =>
{
A31MusicSoAaAl a31MusicSoAaAl = new A31MusicSoAaAl();
MainPage.MainFrameLayout.AddChidren(a31MusicSoAaAl);
a31MusicSoAaAl.Show(a31, album, albumMusiclist);
};
}
}
#endregion
}
public void pushList(A31MusicModel a31, object tag, string listName)
{
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>" + a31.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 i = 0;
foreach (var tempMusicInfo in a31.CurrentPlayMusicInfoList)
{
i++;
sb.AppendLine("<Track" + i + ">");
sb.AppendLine("<URL>" + tempMusicInfo.URL + "</URL>");
sb.AppendLine("<Metadata><?xml version="1.0" encoding="UTF-8"?>");
sb.AppendLine("<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:song="www.wiimu.com/song/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">");
sb.AppendLine("<upnp:class>object.item.audioItem.musicTrack</upnp:class>");
sb.AppendLine("<item id="0">");
sb.AppendLine("<song:subid></song:subid>");
sb.AppendLine("<song:description>unknown</song:description>");
sb.AppendLine("<song:skiplimit>6</song:skiplimit>");
sb.AppendLine("<song:id>" + tempMusicInfo.ID + "</song:id>");
sb.AppendLine("<song:like>0</song:like>");
sb.AppendLine("<song:singerid>0</song:singerid>");
sb.AppendLine("<song:albumid>" + tempMusicInfo.AlbumId + "</song:albumid>");
sb.AppendLine("<res protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;" duration="" + tempMusicInfo.Duration + "">" + tempMusicInfo.URL + "</res>");
sb.AppendLine("<dc:title>" + tempMusicInfo.Title + "</dc:title>");
sb.AppendLine("<dc:creator>DJ Sanny J</dc:creator>");
sb.AppendLine("<upnp:artist>" + tempMusicInfo.Artist + "</upnp:artist>");
sb.AppendLine("<upnp:album>" + tempMusicInfo.Album + "</upnp:album>");
sb.AppendLine("<upnp:albumArtURI>unknown</upnp:albumArtURI>");
sb.AppendLine("</item>");
sb.AppendLine("</DIDL-Lite>");
sb.AppendLine("</Metadata>");
sb.AppendLine("<Id>" + tempMusicInfo.ID + "</Id>");
sb.AppendLine("<Source>iPhone5s_ttpod_search</Source>");
sb.AppendLine("<Key>" + tempMusicInfo.URL + "</Key>");
sb.AppendLine("</Track" + i + ">");
}
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("" + tag + "");
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();
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 { }
}
}
}