using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using Shared.SimpleControl.R;
|
using Shared.SimpleControl.Phone;
|
using Shared.SimpleControl;
|
using Shared.Net;
|
|
namespace Shared.SimpleControl.Phone.Music
|
{
|
/// <summary>
|
///我的喜爱
|
/// </summary>
|
class A31LikeList : FrameLayout
|
{
|
/// <summary>
|
/// 喜爱音乐
|
/// </summary>
|
Button mylike;
|
/// <summary>
|
/// 喜爱电台
|
/// </summary>
|
Button mycn;
|
bool isExited;
|
|
public void Show (A31MusicModel a31)
|
{
|
|
AddChidren (new Button {
|
Height = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
});
|
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (100),
|
Y = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
};
|
AddChidren (topFrameLayout);
|
|
var lovelistName = new Button {
|
TextID = MyInternationalizationString.Musiclike,
|
TextColor=SkinStyle.Current.MusicTextColor,
|
};
|
topFrameLayout.AddChidren (lovelistName);
|
|
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 TtopFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (100),
|
Y = Application.GetRealHeight (130),
|
BackgroundColor = SkinStyle.Current.MusicMiddleBackgroundColor,
|
};
|
AddChidren (TtopFrameLayout);
|
|
//喜爱音乐
|
var mylikerow = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
Width = Application.GetRealWidth (319),
|
};
|
TtopFrameLayout.AddChidren (mylikerow);
|
|
mylike = new Button {
|
TextID = MyInternationalizationString.likemusic,
|
TextColor = 0xffFE5E00,
|
|
};
|
mylikerow.AddChidren (mylike);
|
|
var ther = new Button {
|
Height = Application.GetRealHeight (100),
|
Width = Application.GetRealWidth (2),
|
X = Application.GetRealHeight (320),
|
//BackgroundColor = 0xFF2F2F2F,
|
BackgroundColor = SkinStyle.Current.MusicLineColor,
|
};
|
TtopFrameLayout.AddChidren (ther);
|
|
//喜爱电台
|
var mycnrow = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
X = Application.GetRealWidth (320),
|
Width = Application.GetRealWidth (321),
|
};
|
TtopFrameLayout.AddChidren (mycnrow);
|
|
mycn = new Button {
|
TextID = MyInternationalizationString.likecn,
|
TextColor=SkinStyle.Current.MusicTextColor,
|
};
|
mycnrow.AddChidren (mycn);
|
|
var likelist = new VerticalScrolViewLayout {
|
Height = Application.GetRealHeight (Application.DesignHeight - 100 - 100 - 36),
|
Y = TtopFrameLayout.Bottom,
|
BackgroundColor =SkinStyle.Current.MusicVerticalScrolViewLayout,
|
};
|
AddChidren (likelist);
|
//d2d2d2
|
#region 喜爱音乐
|
List<Button> buttonList = new List<Button> (100);
|
for (int i = 0; i < a31.LoveMusicInfoList.Count; i++) {
|
var musicInfo = a31.LoveMusicInfoList [i];
|
var likemusic = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
LineColor = SkinStyle.Current.MusicRowLayoutLineColor,
|
};
|
likelist.AddChidren (likemusic);
|
|
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",
|
};
|
likemusic.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 songmker = new Button {
|
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (50),
|
TextAlignment = TextAlignment.BottomLeft,
|
X = Application.GetRealWidth (100),
|
Text = a31.LoveMusicInfoList [i].Title,
|
Tag = musicInfo,
|
TextColor=SkinStyle.Current.MusicTextColor,
|
};
|
likemusic.AddChidren (songmker);
|
|
|
var artists = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (40),
|
TextAlignment = TextAlignment.TopLeft,
|
X = Application.GetRealWidth (100),
|
Y = songmker.Bottom,
|
//TextColor = 0x75ffffff,
|
Text = musicInfo.Artist + "-" + musicInfo.Album,
|
Tag = musicInfo,
|
TextColor = SkinStyle.Current.MusicArtistTextColor,
|
};
|
likemusic.AddChidren (artists);
|
|
var del = new Button {
|
TextID = MyInternationalizationString.Musicdel,
|
BackgroundColor = 0xFFFF0000,
|
Tag = musicInfo,
|
};
|
del.MouseUpEventHandler += (sender1, e1) => {
|
a31.LoveMusicInfoList.Remove (del.Tag as MusicInfo);
|
likemusic.RemoveFromParent ();
|
A31MusicModel.Save ();
|
};
|
likemusic.AddRightView (del);
|
|
EventHandler<MouseEventArgs> musics = (sender, e) => {
|
likemusic.BackgroundColor = 0xffFE5E00;
|
System.Threading.Tasks.Task.Run (() => {
|
System.Threading.Thread.Sleep (50);
|
Application.RunOnMainThread (() => {
|
//先移除当前控件的前面那个控件
|
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 (a31.LoveMusicInfoList);
|
//a31playMusic.Source = "SONGLIST-NETWORK";
|
a31.A31PlayStatus.Title = songmker.Text;
|
System.Threading.Tasks.Task.Run (() => {
|
pushList (a31, songmker.Tag as MusicInfo, Language.StringByID (MyInternationalizationString.likemusic));
|
});
|
|
});
|
});
|
};
|
|
songmker.MouseUpEventHandler += musics;
|
artists.MouseUpEventHandler += musics;
|
|
}
|
#endregion
|
|
mylike.MouseUpEventHandler += (sender, e) => {
|
mylike.TextColor = 0xffFE5E00;
|
mycn.TextColor = SkinStyle.Current.MusicTextColor;// 0xffffffff;
|
likelist.RemoveAll ();
|
for (int i = 0; i < a31.LoveMusicInfoList.Count; i++) {
|
var musicInfo = a31.LoveMusicInfoList [i];
|
var likemusic = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
LineColor = SkinStyle.Current.MusicRowLayoutLineColor,
|
};
|
likelist.AddChidren (likemusic);
|
|
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",
|
};
|
likemusic.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 songmker = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealWidth (50),
|
Text = a31.LoveMusicInfoList [i].Title,
|
TextAlignment = TextAlignment.BottomLeft,
|
X = Application.GetRealWidth (100),
|
Tag = musicInfo,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
likemusic.AddChidren (songmker);
|
|
|
var artists = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (50),
|
TextAlignment = TextAlignment.TopLeft,
|
X = Application.GetRealWidth (100),
|
Y = songmker.Bottom,
|
//TextColor = 0x75ffffff,
|
Text = musicInfo.Artist + "-" + musicInfo.Album,
|
Tag = musicInfo,
|
TextColor = SkinStyle.Current.MusicArtistTextColor,
|
};
|
likemusic.AddChidren (artists);
|
|
var del = new Button {
|
TextID = MyInternationalizationString.Musicdel,
|
BackgroundColor = 0xFFFF0000,
|
Tag = musicInfo,
|
};
|
del.MouseUpEventHandler += (sender1, e1) => {
|
a31.LoveMusicInfoList.Remove (musicInfo);
|
likemusic.RemoveFromParent ();
|
A31MusicModel.Save ();
|
};
|
likemusic.AddRightView (del);
|
|
EventHandler<MouseEventArgs> musics = (sender1, e1) => {
|
likemusic.BackgroundColor = 0xffFE5E00;
|
System.Threading.Tasks.Task.Run (() => {
|
System.Threading.Thread.Sleep (50);
|
Application.RunOnMainThread (() => {
|
//先移除当前控件的前面那个控件
|
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 (a31.LoveMusicInfoList);
|
//a31playMusic.Source = "SONGLIST-NETWORK";
|
a31.A31PlayStatus.Title = songmker.Text;
|
System.Threading.Tasks.Task.Run (() => {
|
|
pushList (a31, songmker.Tag as MusicInfo, Language.StringByID (MyInternationalizationString.likemusic));
|
});
|
|
|
});
|
});
|
};
|
|
songmker.MouseUpEventHandler += musics;
|
artists.MouseUpEventHandler += musics;
|
|
}
|
};
|
|
mycn.MouseUpEventHandler += (sender, e) => {
|
mylike.TextColor = SkinStyle.Current.MusicTextColor;// 0xffffffff;
|
mycn.TextColor = 0xffFE5E00;
|
likelist.RemoveAll ();
|
|
for (int i = 0; i < a31.CnLoveRadioInfoList.Count; i++) {
|
var musicInfo = a31.CnLoveRadioInfoList [i];
|
|
var cnrow = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
LineColor = SkinStyle.Current.MusicRowLayoutLineColor,
|
};
|
likelist.AddChidren (cnrow);
|
|
var cntitle = 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",
|
//UnSelectedImagePath = System.IO.File.Exists (musicInfo.Image) ? musicInfo.Image : "MusicIcon/musicplay1.png",
|
};
|
cnrow.AddChidren (cntitle);
|
|
var cnsongmker = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealWidth (100),
|
Text = musicInfo.Title,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (100),
|
Tag = musicInfo,
|
TextColor=SkinStyle.Current.MusicTextColor,
|
};
|
cnrow.AddChidren (cnsongmker);
|
|
var del = new Button {
|
TextID = MyInternationalizationString.Musicdel,
|
BackgroundColor = 0xFFFF0000,
|
Tag = musicInfo,
|
};
|
del.MouseUpEventHandler += (sender1, e1) => {
|
a31.CnLoveRadioInfoList.Remove (del.Tag as MusicInfo);
|
cnrow.RemoveFromParent ();
|
A31MusicModel.Save ();
|
};
|
cnrow.AddRightView (del);
|
|
cnsongmker.MouseUpEventHandler += (sender2, e2) => {
|
cnrow.BackgroundColor = 0xffFE5E00;
|
System.Threading.Tasks.Task.Run (() => {
|
System.Threading.Thread.Sleep (50);
|
Application.RunOnMainThread (() => {
|
//先移除当前控件的前面那个控件
|
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 (a31.CnLoveRadioInfoList);
|
//a31playMusic.Source = "RADIO-NETWORK";
|
a31.A31PlayStatus.Title = cnsongmker.Text;
|
System.Threading.Tasks.Task.Run (() => {
|
CnpushList (a31, cnsongmker.Tag as MusicInfo, Language.StringByID (MyInternationalizationString.likecn));
|
});
|
});
|
});
|
};
|
}
|
};
|
|
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 {
|
|
}
|
}
|
});
|
|
}
|
|
/// <summary>
|
/// 收藏列表音乐播放
|
/// </summary>
|
/// <param name="a31"></param>
|
/// <param name="tag"></param>
|
/// <param name="listName"></param>
|
public void pushList (A31MusicModel a31, MusicInfo musicInfo, string listName)
|
{
|
//最大发送的条数
|
int maxCount = 50;
|
//找出当前点击音乐的索引
|
int statIndex = a31.LoveMusicInfoList.FindIndex ((obj) => { return obj == musicInfo; });
|
//点击后面还有多少条音乐
|
int count = a31.LoveMusicInfoList.Count - statIndex;
|
int endIndex = 0;
|
if (maxCount < count) {
|
//如果后面的音乐大于最大数,设置后面数据的最大索引
|
endIndex = statIndex + maxCount - 1;
|
} else {
|
//如果后面数据不多,就用总数减去最大条数,得到开始索引
|
statIndex = a31.LoveMusicInfoList.Count - maxCount - 1;
|
endIndex = a31.LoveMusicInfoList.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>" + listName + "</ListName>");
|
sb.AppendLine ("<ListInfo>");
|
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 playNumber = 1;
|
for (int trackNumber = 1, index = statIndex; index <= endIndex; trackNumber++, index++) {
|
var tempMusicInfo = a31.CurrentPlayMusicInfoList [index];
|
//找出当前音乐播放的序号
|
if (musicInfo == tempMusicInfo) {
|
playNumber = 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>");//iPhone5s_ttpod_search
|
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 (a31.IPAddress, a31.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>" + playNumber + "</Index>");
|
playString.AppendLine ("</u:PlayQueueWithIndex>");
|
playString.AppendLine ("</s:Body>");
|
playString.AppendLine ("</s:Envelope>");
|
|
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 {
|
|
}
|
}
|
|
/// <summary>
|
///收藏列表电台播放
|
/// </summary>
|
/// <param name="a31"></param>
|
/// <param name="tag"></param>
|
/// <param name="listName"></param>
|
public void CnpushList (A31MusicModel a31, MusicInfo musicInfo, string listName)
|
{
|
|
StringBuilder sb = new StringBuilder ();
|
sb.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
|
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 ("<?xml version="1.0" ?>");
|
sb.AppendLine ("<PlayList>");
|
sb.AppendLine ("<ListName>" + listName + "</ListName>");
|
sb.AppendLine ("<ListInfo>");
|
sb.AppendLine ("<Radio>1</Radio>");
|
sb.AppendLine ("<SourceName>TuneIn</SourceName>");
|
sb.AppendLine ("<TrackNumber>1</TrackNumber>");
|
sb.AppendLine ("<SearchUrl>http://opml.radiotime.com/Tune.ashx?id=s112201&amp;partnerId=yvcOjvJP</SearchUrl>");
|
sb.AppendLine ("<Quality>3</Quality>");
|
sb.AppendLine ("<RealIndex>0</RealIndex>");
|
sb.AppendLine ("<SrcParent></SrcParent>");
|
sb.AppendLine ("<PicUrl></PicUrl>");
|
sb.AppendLine ("</ListInfo>");
|
sb.AppendLine ("<Tracks>");
|
|
var url = musicInfo.URL;
|
|
if (url != null) {
|
url = url.TrimEnd ('\n').Replace ("&", "&amp;");
|
} else {
|
return;
|
}
|
sb.AppendLine ("<Track" + 1 + ">");
|
sb.AppendLine ("<Source>TuneIn</Source>");
|
sb.AppendLine ("<URL>" + url + "</URL>");
|
sb.AppendLine ("<Source>TuneIn</Source>");
|
sb.AppendLine ("<Id>0</Id>");
|
sb.AppendLine ("<Key>http://so.ard.iyyin.com/s/song_with_out?q=%E8%8A%B1%E9%83%BD%E7%94%B5%E5%8F%B0+100.5+%28%E6%B5%81%E8%A1%8C%E9%9F%B3%E4%B9%90%E5%89%8D40%29%20TuneIn&amp;size=50&amp;page=1</Key>");
|
sb.AppendLine ("<Metadata>");
|
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&gt;");
|
sb.AppendLine ("&lt;song:bitrate&gt;0&lt;/song:bitrate&gt;");
|
sb.AppendLine ("&lt;song:id&gt;0&lt;/song:id&gt;");
|
sb.AppendLine ("&lt;song:singerid&gt;0&lt;/song:singerid&gt;");
|
sb.AppendLine ("&lt;song:albumid&gt;0&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;1000&quot;&gt;" + url + "&lt;/res&gt;");
|
sb.AppendLine ("&lt;dc:title&gt;" + musicInfo.Title + "&lt;/dc:title&gt;");
|
sb.AppendLine ("&lt;upnp:artist&gt;TuneIn&lt;/upnp:artist&gt;");
|
sb.AppendLine ("&lt;upnp:album&gt;&lt;/upnp:album&gt;");
|
sb.AppendLine ("&lt;upnp:albumArtURI&gt;" + musicInfo.Image + "&lt;/upnp:albumArtURI&gt;");
|
sb.AppendLine ("&lt;/item&gt;");
|
sb.AppendLine ("&lt;/DIDL-Lite&gt;");
|
sb.AppendLine ("</Metadata>");
|
sb.AppendLine ("</Track" + 1 + ">");
|
|
sb.AppendLine ("</Tracks>");
|
sb.AppendLine ("</PlayList>");
|
sb.AppendLine ("</QueueContext>");
|
sb.AppendLine ("</u:CreateQueue>");
|
sb.AppendLine ("</s:Body>");
|
sb.AppendLine ("</s:Envelope>");
|
//sendMusicLists(a31.IPAddress, a31.Port, "CreateQueue", sb.ToString());
|
sendMusicLists (a31.IPAddress, a31.Port, "CreateQueue", sb.ToString ());
|
|
StringBuilder playString = new StringBuilder ();
|
playString.AppendLine ("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>");
|
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>" + 1 + "</Index>");
|
playString.AppendLine ("</u:PlayQueueWithIndex>");
|
playString.AppendLine ("</s:Body>");
|
playString.AppendLine ("</s:Envelope>");
|
|
play (a31.IPAddress, a31.Port, playString.ToString ());
|
|
}
|
|
void CnsendMusicLists (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 Cnplay (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 { }
|
}
|
|
/// <summary>
|
/// 读取电台信息
|
/// </summary>
|
/// <returns>读取到的电台组列表信息,读取不到反馈为null</returns>
|
string readRadioList (string url)
|
{
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
|
webClient.Proxy = null;
|
webClient.Headers.Add ("Content-type", "plain/text; charset=UTF-8");
|
webClient.Headers.Add ("Accept-Language", "zh-cn");
|
try {
|
byte [] recevieBytes = webClient.DownloadData (new Uri (url));
|
return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
} catch (Exception e) {
|
return null;
|
}
|
}
|
}
|
}
|