using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using Shared.SimpleControl;
|
using Shared.SimpleControl.Phone.Music;
|
using Shared.SimpleControl.R;
|
|
namespace SmartHome.UI.SimpleControl.Phone.Music
|
{
|
class A31NewPage : FrameLayout
|
{
|
public override void RemoveFromParent ()
|
{
|
base.RemoveFromParent ();
|
if (readThread != null && readThread.IsAlive) {
|
readThread.Abort ();
|
}
|
}
|
|
public void Show (string path,string listname)
|
{
|
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 whatnew = new Button {
|
//TextID = MyInternationalizationString.Musiclike,
|
Text = listname.ToUpper(),
|
TextColor=SkinStyle.Current.MusicTextColor,
|
};
|
topFrameLayout.AddChidren (whatnew);
|
|
var Search = new Button {
|
Width = Application.GetMinRealAverage (60),
|
Height = Application.GetMinRealAverage (80),
|
X = Application.GetRealWidth (535),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/seekdevice.png",
|
};
|
//topFrameLayout.AddChidren (Search);
|
Search.MouseUpEventHandler += (sender, e) => {
|
|
};
|
|
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 {
|
Y = topFrameLayout.Bottom,
|
Height = Application.GetRealHeight (Application.DesignHeight - 136),
|
BackgroundColor =SkinStyle.Current.MusicVerticalScrolViewLayout,
|
};
|
AddChidren (middle);
|
|
#region 标题PLAYLISTS
|
|
//var top = new FrameLayout {
|
// Height = Application.GetRealHeight (96),
|
//};
|
//middle.AddChidren (top);
|
|
//var playname = new Button {
|
// Width = Application.GetRealWidth (300),
|
// X = Application.GetRealWidth (30),
|
// TextAlignment = TextAlignment.CenterLeft,
|
// Text = "PLAYLISTS",
|
//};
|
//top.AddChidren (playname);
|
|
//var more = new Button {
|
// Width = Application.GetRealWidth (200),
|
// X = Application.GetRealWidth (420),
|
// Text = "More",
|
//};
|
////top.AddChidren (more);
|
|
//var nextmore = new Button {
|
// Width = Application.GetRealWidth (87),
|
// Height = Application.GetRealHeight (100),
|
// UnSelectedImagePath = "MusicIcon/Next.png",
|
// TextAlignment = TextAlignment.CenterLeft,
|
// X = Application.GetRealWidth (550),
|
// Gravity = Gravity.CenterVertical,
|
//};
|
////top.AddChidren (nextmore);
|
|
//var ther = new FrameLayout {
|
// Height = Application.GetRealHeight (4),
|
// BackgroundColor = 0xFF4D4D4D,
|
// Y=top.Bottom,
|
//};
|
//middle.AddChidren (ther);
|
|
//var PlayLists = Tidal.TempMusicInfoList.FindAll ((obj) => obj.Tag.ToString () == "NewPlayLists");
|
//FrameLayout rowLayout = null;
|
//for (int i1 = 0; i1 < PlayLists.Count; i1++) {
|
// if (i1 > 3) {
|
// continue;
|
// }
|
// if (i1 % 2 == 0) {
|
// rowLayout = new FrameLayout {
|
// Y = ther.Bottom,
|
// Height = Application.GetRealHeight (254),
|
// };
|
// middle.AddChidren (rowLayout);
|
// //上下间隔距离为20;
|
// var rowLayout1 = new FrameLayout {
|
// Height = Application.GetRealHeight (20),
|
// };
|
// if (i1 < 2) {
|
// middle.AddChidren (rowLayout1);
|
// }
|
// }
|
// FrameLayout equipmentLayout = new FrameLayout {
|
// Width = Application.GetRealWidth (310),
|
// };
|
// rowLayout.AddChidren (equipmentLayout);
|
|
// var btniamge = new Button {
|
// Width = Application.GetRealWidth (270),
|
// Height = Application.GetRealHeight (200),
|
// X = Application.GetRealWidth (20),
|
// //Gravity = Gravity.CenterHorizontal,
|
// UnSelectedImagePath = System.IO.File.Exists (PlayLists [i1].Image) ? PlayLists [i1].Image : "MusicIcon/musicplay1.png",
|
// };
|
// equipmentLayout.AddChidren (btniamge);
|
|
// var btntitle = new Button {
|
// Y = Application.GetRealHeight (350),
|
// X=Application.GetRealWidth(20),
|
// //Gravity=Gravity.CenterLeft,
|
// Text = PlayLists [i1].Title,
|
// };
|
// equipmentLayout.AddChidren (btntitle);
|
|
// var btnsize = new Button {
|
// Width = Application.GetRealWidth (50),
|
// Height = Application.GetRealHeight (35),
|
// X = Application.GetRealWidth (248),
|
// Y = Application.GetRealHeight (30),
|
// TextAlignment = TextAlignment.Center,
|
// };
|
|
// //equipmentLayout.AddChidren (btnsize);
|
|
|
|
// if (i1 % 2 == 1) {
|
// equipmentLayout.Width = Application.GetRealWidth (310);
|
// equipmentLayout.X = Application.GetRealWidth (330);
|
// equipmentLayout.Height = Application.GetRealHeight (254);
|
// }
|
|
// var th = new FrameLayout {
|
// Height = Application.GetRealHeight (2),
|
// BackgroundColor = 0xFF4D4D4D,
|
// Y = rowLayout.Bottom,
|
// };
|
// if (i1 > 2) {
|
// middle.AddChidren (th);
|
// }
|
|
//}
|
#endregion
|
|
#region 标题ALBUMS
|
|
// var topalbums = new FrameLayout {
|
// Height = Application.GetRealHeight (96),
|
// };
|
// middle.AddChidren (topalbums);
|
|
// var albums = new Button {
|
// Width = Application.GetRealWidth (300),
|
// X = Application.GetRealWidth (30),
|
// TextAlignment = TextAlignment.CenterLeft,
|
// Text = "ALBUMS",
|
//};
|
// topalbums.AddChidren (albums);
|
|
// var morealbums = new Button {
|
// Width = Application.GetRealWidth (200),
|
// X = Application.GetRealWidth (420),
|
// Text = "More",
|
//};
|
// topalbums.AddChidren (morealbums);
|
|
// var nextalbums = new Button {
|
// Width = Application.GetRealWidth (87),
|
// Height = Application.GetRealHeight (100),
|
// UnSelectedImagePath = "MusicIcon/Next.png",
|
// TextAlignment = TextAlignment.CenterLeft,
|
// X = Application.GetRealWidth (550),
|
// Gravity = Gravity.CenterVertical,
|
//};
|
// topalbums.AddChidren (nextalbums);
|
|
// var theralbums = new FrameLayout {
|
// Height = Application.GetRealHeight (4),
|
// BackgroundColor = 0xFF4D4D4D,
|
// Y = topalbums.Bottom,
|
//};
|
// middle.AddChidren (theralbums);
|
|
|
// FrameLayout rowLayoutalbums = null;
|
// for (int i2 = 0; i2 < 4; i2++) {
|
// if (i2 % 2 == 0) {
|
// rowLayoutalbums = new FrameLayout {
|
// Y = theralbums.Bottom,
|
// Height = Application.GetRealHeight (254),
|
// };
|
// middle.AddChidren (rowLayoutalbums);
|
// //上下间隔距离为20;
|
// var rowLayout2 = new FrameLayout {
|
// Height = Application.GetRealHeight (20),
|
// };
|
// if (i2 < 2) {
|
// middle.AddChidren (rowLayout2);
|
// }
|
// }
|
// FrameLayout equipmentLayout = new FrameLayout {
|
// Width = Application.GetRealWidth (310),
|
// BackgroundColor = 0xff563838,
|
// };
|
|
// rowLayoutalbums.AddChidren (equipmentLayout);
|
// if (i2 % 2 == 1) {
|
// equipmentLayout.Width = Application.GetRealWidth (310);
|
// equipmentLayout.X = Application.GetRealWidth (330);
|
// equipmentLayout.Height = Application.GetRealHeight (254);
|
// }
|
// var th1 = new FrameLayout {
|
// Height = Application.GetRealHeight (2),
|
// BackgroundColor = 0xFF4D4D4D,
|
// Y = rowLayoutalbums.Bottom,
|
// };
|
// if (i2>2) {
|
// middle.AddChidren (th1);
|
// }
|
// }
|
|
#endregion
|
|
#region 标题TRACKS
|
|
var toptracks = new FrameLayout {
|
Height = Application.GetRealHeight (96),
|
};
|
//middle.AddChidren (toptracks);
|
|
var tracks = new Button {
|
Width = Application.GetRealWidth (300),
|
X = Application.GetRealWidth (30),
|
TextAlignment = TextAlignment.CenterLeft,
|
Text = "TRACKS",
|
};
|
//toptracks.AddChidren (tracks);
|
|
var moretracks = new Button {
|
Width = Application.GetRealWidth (200),
|
X = Application.GetRealWidth (420),
|
Text = "More",
|
};
|
//toptracks.AddChidren (moretracks);
|
moretracks.MouseUpEventHandler += (sender, e) => {
|
|
};
|
|
var nexttracks = new Button {
|
Width = Application.GetRealWidth (87),
|
Height = Application.GetRealHeight (100),
|
UnSelectedImagePath = "MusicIcon/Next.png",
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth (550),
|
Gravity = Gravity.CenterVertical,
|
};
|
//toptracks.AddChidren (nexttracks);
|
|
var thertracks = new FrameLayout {
|
Height = Application.GetRealHeight (4),
|
BackgroundColor = 0xFF121212,
|
//Y = topalbums.Bottom,
|
};
|
//middle.AddChidren (thertracks);
|
|
|
var list = Tidal.TempMusicInfoList.FindAll ((obj) => obj.Tag.ToString () ==path);
|
|
for (int i = 0; i < list.Count; i++) {
|
var musicInfo = list [i];
|
var row = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
LineColor = SkinStyle.Current.MusicRowLayoutLineColor,
|
Y = thertracks.Bottom,
|
};
|
middle.AddChidren (row);
|
|
var imageBtn = new Button {
|
Width = Application.GetRealWidth (61),
|
Height = Application.GetRealHeight (61),
|
X = Application.GetRealWidth (20),
|
Gravity = Gravity.CenterVertical,
|
Radius = (uint)Application.GetRealHeight (4),
|
UnSelectedImagePath = System.IO.File.Exists (musicInfo.Image) ? musicInfo.Image : "MusicIcon/musicplay1.png",
|
Tag = musicInfo,
|
};
|
row.AddChidren (imageBtn);
|
|
var listmusic = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (50),
|
Text = musicInfo.Title,
|
TextAlignment = TextAlignment.BottomLeft,
|
X = Application.GetRealWidth (100),
|
Tag = musicInfo,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
row.AddChidren (listmusic);
|
|
var artists = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (50),
|
TextAlignment = TextAlignment.TopLeft,
|
X = Application.GetRealWidth (100),
|
Y = listmusic.Bottom,
|
//TextColor = 0x75ffffff,
|
Text = musicInfo.Artist,
|
Tag = musicInfo,
|
TextColor = SkinStyle.Current.MusicArtistTextColor,
|
};
|
row.AddChidren (artists);
|
|
EventHandler<MouseEventArgs> TrackMusic = (sender, e) => {
|
row.BackgroundColor = 0xffFE5E00;
|
System.Threading.Tasks.Task.Run (() => {
|
Application.RunOnMainThread (() => {
|
|
for (int a = MainPage.MainFrameLayout.ChildrenCount - 1; 0 <= a; a--) {
|
var viwe = MainPage.MainFrameLayout.GetChildren (a);
|
if (viwe.GetType () == typeof (A31NewPage)) {
|
viwe.RemoveFromParent ();
|
} else { break; }
|
}
|
MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1);
|
MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1);
|
MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1);
|
|
A31PlayMusicPage a31PlayMusicPage = new A31PlayMusicPage ();
|
MainPage.MainFrameLayout.AddChidren (a31PlayMusicPage);
|
a31PlayMusicPage.Show (new List<MusicInfo> ());
|
A31MusicModel.Current.A31PlayStatus.Title = listmusic.Text;
|
|
System.Threading.Tasks.Task.Run (() => {
|
tidalpushList (listmusic.Tag as MusicInfo, list);
|
});
|
});
|
});
|
};
|
imageBtn.MouseUpEventHandler += TrackMusic;
|
listmusic.MouseUpEventHandler += TrackMusic;
|
artists.MouseUpEventHandler += TrackMusic;
|
}
|
|
readThread =new System.Threading.Thread(() => {
|
for (int i = 0; i < list.Count; i++) {
|
Tidal.ReadRealUrl (list [i]);
|
}
|
});
|
readThread.Start ();
|
#endregion
|
}
|
|
static System.Threading.Thread readThread;
|
|
static void pushMusicList (List<MusicInfo> musicList)
|
{
|
|
var 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>tidal</ListName>");
|
sb.AppendLine ("<ListInfo>");
|
sb.AppendLine ("<SourceName>Tidal</SourceName>");
|
sb.AppendLine ("<TrackNumber>" + musicList.Count + "</TrackNumber>");
|
sb.AppendLine ("<SearchUrl>searchurl</SearchUrl>");
|
sb.AppendLine ("</ListInfo>");
|
sb.AppendLine ("<Tracks>");
|
|
for (int i = 1; i <= musicList.Count; i++) {
|
var tempMusicInfo = musicList [i - 1];
|
sb.AppendLine ("<Track" + i + ">");
|
sb.AppendLine ("<URL>" + tempMusicInfo.URL + "</URL>");
|
sb.AppendLine ("<Source>Tidal</Source>");
|
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;" + tempMusicInfo.URL + "&lt;/res&gt;");
|
sb.AppendLine ("&lt;dc:title&gt;" + tempMusicInfo.Title + "&lt;/dc:title&gt;");
|
sb.AppendLine ("&lt;upnp:artist&gt;" + tempMusicInfo.Artist + "&lt;/upnp:artist&gt;");
|
sb.AppendLine ("&lt;upnp:album&gt;&lt;/upnp:album&gt;");
|
sb.AppendLine ("&lt;upnp:albumArtURI&gt;" + tempMusicInfo.Image + "&lt;/upnp:albumArtURI&gt;");
|
sb.AppendLine ("&lt;/item&gt;");
|
sb.AppendLine ("&lt;/DIDL-Lite&gt;");
|
sb.AppendLine ("</Metadata>");
|
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 ());
|
}
|
|
static System.Threading.Thread thread;
|
public static void tidalpushList (MusicInfo musicInfo, List<MusicInfo> tidallist)
|
{
|
if (readThread != null && readThread.IsAlive) {
|
readThread.Abort ();
|
readThread = null;
|
}
|
//后台推送音乐
|
if (thread != null && thread.IsAlive) {
|
thread.Abort ();
|
thread = null;
|
}
|
|
Tidal.ReadRealUrl (musicInfo);
|
//如果没有拿到当前的再拿一次
|
if (musicInfo.URL.StartsWith ("https://meta.airable.io")) {
|
Tidal.ReadRealUrl (musicInfo);
|
}
|
|
var musicList = tidallist.FindAll ((obj) => !obj.URL.StartsWith ("https://meta.airable.io"));
|
|
pushMusicList (musicList);
|
playMusicByIndex (musicList.FindIndex ((obj) => obj == musicInfo) + 1);
|
|
thread = new System.Threading.Thread ((obj) => {
|
var tempList = tidallist.FindAll ((m) => m.URL.StartsWith ("https://meta.airable.io"));
|
for (int i = 0; i < tempList.Count; i++) {
|
var tempMusicInfo = tempList [i];
|
Tidal.ReadRealUrl (tempMusicInfo);
|
if (!tempMusicInfo.URL.StartsWith ("https://meta.airable.io")) {
|
musicList.Add (tempMusicInfo);
|
pushMusicList (musicList);
|
}
|
}
|
});
|
thread.Start ();
|
}
|
|
static void playMusicByIndex (int playIndex)
|
{
|
var 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>tidal</QueueName>");
|
playString.AppendLine ("<Index>" + playIndex + "</Index>");
|
playString.AppendLine ("</u:PlayQueueWithIndex>");
|
playString.AppendLine ("</s:Body>");
|
playString.AppendLine ("</s:Envelope>");
|
|
play (A31MusicModel.Current.IPAddress, A31MusicModel.Current.Port, playString.ToString ());
|
}
|
|
static void sendMusicLists (string ip, int port, string soapAction, string listInfo)
|
{
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (5000);
|
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 { }
|
}
|
|
static void play (string ip, int port, string info)
|
{
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (5000);
|
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{ }
|
}
|
|
}
|
}
|