using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using Shared.SimpleControl.R;
|
|
namespace Shared.SimpleControl.Phone.Music
|
{
|
/// <summary>
|
/// SD/USB界面
|
/// </summary>
|
class A31Usbmusic : FrameLayout
|
{
|
|
Button seletcedbutton = null;
|
bool isExited;
|
|
public void show (A31MusicModel a31, List<MusicInfo> musicInfoList)
|
{
|
this.AddChidren (new Button {
|
Height = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
});
|
|
var topFrameLayout = new FrameLayout {
|
Height = Application.GetRealHeight (90),
|
Y = Application.GetRealHeight (36),
|
BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
|
};
|
AddChidren (topFrameLayout);
|
|
var SDlistName = new Button {
|
TextID = MyInternationalizationString.SDcard,
|
TextColor=SkinStyle.Current.MusicTextColor,
|
};
|
topFrameLayout.AddChidren (SDlistName);
|
|
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 middle = new VerticalScrolViewLayout ();
|
middle.Y = topFrameLayout.Bottom;
|
middle.Height = Application.GetRealHeight (Application.DesignHeight - 136);
|
middle.BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout;
|
this.AddChidren (middle);
|
|
EventHandler<MouseEventArgs> ddd = (sender, e) => {
|
if (seletcedbutton != null) {
|
seletcedbutton.Parent.BackgroundColor = 0xff000000;
|
}
|
seletcedbutton = sender as Button;
|
};
|
|
int number = 0;
|
List<Button> buttonList = new List<Button> (100);
|
if (musicInfoList != null) {
|
foreach (var musicInfo in musicInfoList) {
|
//musicInfo.filename = "http://" + "192.168.1.107"+ ":" + "/httpapi.asp?command=setPlayerCmd:playLocalList/media/sda1/music" + musicInfo.Title;
|
number++;
|
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 addlikelits = new Button {
|
Width = Application.GetRealWidth (72),
|
Height = Application.GetRealHeight (58),
|
X = Application.GetRealWidth (560),
|
UnSelectedImagePath = "MusicIcon/add.png",
|
Gravity = Gravity.CenterVertical,
|
};
|
usbrowL.AddChidren (addlikelits);
|
addlikelits.MouseUpEventHandler += (sender, e) => {
|
A31MyList A31MyList = new A31MyList ();
|
MainPage.MainFrameLayout.AddChidren (A31MyList);
|
A31MyList.Show (new MusicInfo { SourceType = musicInfo.SourceType, Title = musicInfo.Title, URL = musicInfo.URL, Artist = musicInfo.Artist, Album = musicInfo.Album });
|
};
|
|
var btnMusicName = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (50),
|
TextAlignment = TextAlignment.BottomLeft,
|
X = Application.GetRealWidth (100),
|
Text = musicInfo.Title,
|
Tag = number,
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
usbrowL.AddChidren (btnMusicName);
|
|
var artists = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (50),
|
TextAlignment = TextAlignment.TopLeft,
|
X = Application.GetRealWidth (100),
|
Y = btnMusicName.Bottom,
|
//TextColor = 0x75ffffff,
|
Text = musicInfo.Artist + "-" + musicInfo.Album,
|
Tag = number,
|
TextColor = SkinStyle.Current.MusicArtistTextColor,
|
};
|
usbrowL.AddChidren (artists);
|
|
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 - 3);
|
this.Parent.RemoveAt (this.Parent.ChildrenCount - 2);
|
//移除当前控件界面
|
this.RemoveFromParent ();
|
MainPage.MainFrameLayout.RemoveViewByTag ("A31PlayMusicPage");
|
A31PlayMusicPage a31PlayMusicPage = new A31PlayMusicPage ();
|
MainPage.MainFrameLayout.AddChidren (a31PlayMusicPage);
|
a31PlayMusicPage.Show (new List<MusicInfo> ());
|
a31.A31PlayStatus.Title = btnMusicName.Text;
|
System.Threading.Tasks.Task.Run (() => {
|
playstrinfg (a31.IPAddress, a31.Port, btnMusicName.Tag);
|
});
|
});
|
});
|
};
|
|
btnMusicName.MouseUpEventHandler += musics;
|
artists.MouseUpEventHandler += musics;
|
|
}
|
}
|
|
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 {
|
}
|
}
|
});
|
}
|
|
|
void playstrinfg (string ip, int Port, object tag)
|
{
|
StringBuilder sb = new StringBuilder ();
|
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:PlayQueueWithIndex xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
|
sb.AppendLine ("<QueueName>USBDiskQueue</QueueName>");
|
sb.AppendLine ("<Index>" + tag + "</Index>");
|
sb.AppendLine ("</u:PlayQueueWithIndex>");
|
sb.AppendLine ("</s:Body>");
|
sb.AppendLine ("</s:Envelope>");
|
|
paly (ip, Port, sb.ToString ());
|
}
|
|
void paly (string ip, int port, string s)
|
{
|
|
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 [] bytes = webClient.UploadData (new Uri ("http://" + ip + ":" + port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (s));
|
var ab = System.Text.Encoding.UTF8.GetString (bytes, 0, bytes.Length);
|
} catch { }
|
}
|
|
|
|
/// <summary>
|
/// 播放歌曲
|
/// </summary>
|
/// <param name="Tag"></param>
|
/// <returns></returns>
|
///
|
string playSong (string ip, object Tag)
|
{
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
|
try {
|
byte [] recevieBytes = webClient.DownloadData (new Uri ("http://" + ip + "/httpapi.asp?command=setPlayerCmd:playLocalList" + ":" + Tag));
|
return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
|
} catch {
|
return "";
|
}
|
}
|
|
void sendCommand (string ip, string coutn)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
|
try {
|
byte [] recevieBytes1 = webClient.DownloadData (new Uri ("http://" + ip + "/httpapi.asp?command=setPlayerCmd:" + coutn + ""));
|
} catch (Exception ex) {
|
//this.IPAddress = ex.Message;
|
}
|
});
|
}
|
}
|
}
|