using System;
using System.Collections.Generic;
using System.Text;
using Shared;
using Shared.SimpleControl.Pad;
using Shared.SimpleControl;
using System.Xml;
using Shared.SimpleControl.R;
using System.Security;
using SmartHome;
using com.hdl.on;
namespace Shared.SimpleControl.Pad.Music
{
///
/// 当前音乐播放界面
///
class A31PlayMusicPage : FrameLayout
{
void showSourcePage ()
{
like.Alpha = 1;
like.Enable = true;
list.Alpha = 1;
list.Enable = true;
prev.Alpha = 1;
prev.Enable = true;
next.Alpha = 1;
next.Enable = true;
mode.Alpha = 1;
mode.Enable = true;
SeekBarVol.IsCanMove = true;
switch (A31MusicModel.Current.A31PlayStatus.Source) {
case "QPLAY"://QQ音乐
currentsource.UnSelectedImagePath = "MusicIcon/qqmusic.png";
like.Alpha = 0.5f;
like.Enable = false;
break;
case "AIRPLAY"://酷狗音乐
currentsource.UnSelectedImagePath = "MusicIcon/kumusic.png";
like.Alpha = 0.5f;
like.Enable = false;
SeekBarVol.IsCanMove = false;
break;
case "BLUETOOTH"://蓝牙
currentsource.UnSelectedImagePath = "MusicIcon/bluetooth.png";
SeekBarVol.IsCanMove = false;
like.Alpha = 0.5f;
like.Enable = false;
list.Alpha = 0.5f;
list.Enable = false;
prev.Alpha = 0.5f;
prev.Enable = false;
next.Alpha = 0.5f;
next.Enable = false;
mode.Alpha = 0.5f;
mode.Enable = false;
break;
case "SONGLIST-NETWORK"://本地音乐
currentsource.UnSelectedImagePath = "MusicIcon/musicMusic.png";
break;
case "SONGLIST-LOCAL"://USB
currentsource.UnSelectedImagePath = "MusicIcon/USB.png";
break;
case "RADIO-NETWORK"://在线电台
SeekBarVol.IsCanMove = false;
currentsource.UnSelectedImagePath = "MusicIcon/local.png";
list.Alpha = 1;
list.Enable = true;
prev.Alpha = 0.5f;
prev.Enable = false;
next.Alpha = 0.5f;
next.Enable = false;
mode.Alpha = 0.5f;
mode.Enable = false;
break;
case "STATION-NETWORK"://Pandora电台
SeekBarVol.IsCanMove = false;
currentsource.UnSelectedImagePath = "MusicIcon/pandora.png";
like.Alpha = 0.5f;
like.Enable = false;
prev.Alpha = 0.5f;
prev.Enable = false;
mode.Alpha = 0.5f;
mode.Enable = false;
break;
default:
currentsource.UnSelectedImagePath = "MusicIcon/dlna.png";
SeekBarVol.IsCanMove = false;
like.Alpha = 0.5f;
like.Enable = false;
list.Alpha = 0.5f;
list.Enable = false;
prev.Alpha = 0.5f;
prev.Enable = false;
next.Alpha = 0.5f;
next.Enable = false;
mode.Alpha = 0.5f;
mode.Enable = false;
break;
}
if (A31MusicModel.Current.A31PlayStatus.playSource == "UPnPServer") {
currentsource.UnSelectedImagePath = "MusicIcon/dlna.png";
}
}
public string Source {
set {
if (A31MusicModel.Current.A31PlayStatus.Source != value) {
A31MusicModel.Current.A31PlayStatus.Source = value;
sendCommand ("switchmode:%" + value);
}
}
}
///
/// 当前音乐播放器的名称
///
Button a31sourceName;
///
/// 下一曲
///
Button next;
///
/// 上一曲
///
Button prev;
///
/// 停止/播放
///
Button btnPlay;
///
///当前播放音乐时间
///
Button btnMusicplayTime;
///
/// 音乐总时间
///
Button btnTotalMusicTime;
///
/// 播放音乐时间进度条
///
//Button progressMaxButton;
///
/// 播放进度
///
//Button progressButton;
///
/// 歌名
///
TextView title;
///
/// 静音图标
///
Button btnMute;
Button btnMusicvol;
///
/// 当前音量进度条
///
HorizontalSeekBar horizontalSeekBarVol;
///
/// 快进进度条
///
HorizontalSeekBar SeekBarVol;
///
/// 播放模式:0列表循环,1单曲循环,2随机播放
///
Button mode;
///
/// 显示播放列表
///
Button list;
///
/// 收藏图标
///
Button like;
///
/// 歌手头像
///
Button musicartist;
///
/// 当前播放源图标
///
Button currentsource;
///
/// 当前歌手图像
///
ImageView portrait;
///
/// 当前界面对象
///
static A31PlayMusicPage currentPlayMusic;
FrameLayout middleFrameLayout = new FrameLayout ();
public void Show (List musicInfoList, FrameLayout MusicSourcePage, FrameLayout PalyMusicPage, FrameLayout bordorView)
{
currentPlayMusic = this;
A31MusicModel.Current.CurrentPlayMusicInfoList = musicInfoList;
//更新当前的音乐状态
timerUpdateThread = new System.Threading.Thread (new System.Threading.ThreadStart (() => {
updateStatus ();
})) {
IsBackground = true
};
timerUpdateThread.Start ();
A31MusicSourcePage a31HomepageMusic = new A31MusicSourcePage ();
MusicSourcePage.AddChidren (a31HomepageMusic);
a31HomepageMusic.Show (A31MusicModel.Current, MusicSourcePage, PalyMusicPage, bordorView);
middleFrameLayout.Height = Application.GetRealHeight (Application.DesignHeight);
middleFrameLayout.BackgroundImagePath = "MusicIcon/PlayBackgroun.png";
AddChidren (middleFrameLayout);
//隐藏底层
FrameLayout fra = new FrameLayout {
Y = Application.GetRealHeight (30),
Height = Application.GetRealHeight (106),
};
middleFrameLayout.AddChidren (fra);
a31sourceName = new Button {
Gravity = Gravity.Center,
Text = A31MusicModel.Current.Name,
};
fra.AddChidren (a31sourceName);
like = new Button {
Width = Application.GetRealWidth (106),
Height = Application.GetRealHeight (103),
X = Application.GetRealWidth (40),
UnSelectedImagePath = "MusicIcon/PlayLike.png",
SelectedImagePath = "MusicIcon/PlayLikeSelected.png",
Gravity = Gravity.CenterVertical,
};
fra.AddChidren (like);
like.MouseDownEventHandler += (sender, e) => {
var url = A31MusicModel.Current.A31PlayStatus.TrackURL;
var album = A31MusicModel.Current.A31PlayStatus.Album;
var artist = A31MusicModel.Current.A31PlayStatus.Artist;
if (A31MusicModel.Current.A31PlayStatus.Source == "RADIO-NETWORK") {
like.IsSelected = !like.IsSelected;
if (like.IsSelected) {
if (null == A31MusicModel.Current.CnLoveRadioInfoList.Find ((musicInfo) => {
return url == musicInfo.URL;
})) {
A31MusicModel.Current.CnLoveRadioInfoList.Add (new MusicInfo { Title = title.Text, URL = url, });
}
} else {
A31MusicModel.Current.CnLoveRadioInfoList.RemoveAll ((musicInfo) => {
return url == musicInfo.URL;
});
}
A31MusicModel.Save ();
} else {
like.IsSelected = !like.IsSelected;
if (like.IsSelected) {
if (null == A31MusicModel.Current.LoveMusicInfoList.Find ((musicInfo) => {
return url == musicInfo.URL;
})) {
A31MusicModel.Current.LoveMusicInfoList.Add (new MusicInfo { Title = title.Text, URL = url, Artist = artist, Album = album });
A31MusicModel.Save ();
}
} else {
A31MusicModel.Current.LoveMusicInfoList.RemoveAll ((musicInfo) => {
//也要加歌手名判断
return musicInfo.URL == url;
});
A31MusicModel.Save ();
}
}
//保存
string saveRoomUIName = "A31_" + A31MusicModel.Current.IPAddress;
Shared.IO.FileUtils.WriteFileByBytes (saveRoomUIName,
Shared.SimpleControl.CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (A31MusicModel.Current)));
};
currentsource = new Button {
Width = Application.GetRealWidth (61),
Height = Application.GetRealHeight (81),
X = Application.GetRealWidth (830 - 40 - 61),
Gravity = Gravity.CenterVertical,
};
fra.AddChidren (currentsource);
var color = new FrameLayout {
Width = Application.GetMinRealAverage (600),
Height = Application.GetMinRealAverage (600),
Y = Application.GetRealHeight (250),
BackgroundColor = 0x30FFFFFF,
//BackgroundImagePath = "MusicIcon/PlayPortrait.png",
//Animate= Animate.Rotation,
Radius = (uint)Application.GetMinRealAverage (300),
Gravity = Gravity.CenterHorizontal,
};
middleFrameLayout.AddChidren (color);
portrait = new ImageView {
Width = Application.GetMinRealAverage (550),
Height = Application.GetMinRealAverage (550),
Radius = (uint)Application.GetMinRealAverage (275),
Gravity = Gravity.Center,
ImagePath = "MusicIcon/PlayPortrait.png",
};
color.AddChidren (portrait);
var frameLayout2 = new FrameLayout {
Height = Application.GetRealHeight (103),
Y = Application.GetRealHeight (830 + 100 + 10),
};
middleFrameLayout.AddChidren (frameLayout2);
mode = new Button {
Width = Application.GetRealWidth (94),
Height = Application.GetRealHeight (82),
X = Application.GetRealWidth (40),
Gravity = Gravity.CenterVertical,
};
frameLayout2.AddChidren (mode);
mode.MouseDownEventHandler += Mode_MouseDownEventHandler;
title = new TextView {
Width = Application.GetMinRealAverage (300),
Height = Application.GetMinRealAverage (60),
X = Application.GetRealWidth (265),
Gravity = Gravity.CenterVertical,
TextSize = 15,
Text = "unKnown",
};
frameLayout2.AddChidren (title);
musicartist = new Button {
Width = Application.GetMinRealAverage (300),
Height = Application.GetMinRealAverage (60),
X = Application.GetRealWidth (265),
Y = Application.GetRealHeight (1000),
TextColor = 0x80ffffff,
Text = "unKnown",
};
middleFrameLayout.AddChidren (musicartist);
list = new Button {
Width = Application.GetRealWidth (106),
Height = Application.GetRealHeight (103),
X = Application.GetRealWidth (830 - 40 - 106),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayList.png",
Tag = A31MusicModel.Current.Name,
};
frameLayout2.AddChidren (list);
list.MouseUpEventHandler += (sender, e) => {
MusicSourcePage.RemoveViewByType (typeof (A31PlayList));
A31PlayList listMusic = new A31PlayList ();
MusicSourcePage.AddChidren (listMusic);
listMusic.InitFace (MusicSourcePage);
MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load) + "...");
System.Threading.Tasks.Task.Run (() => {
string PlayListName = "List";
string sourceName = "SourceName";
try {
if (A31MusicModel.Current.A31PlayStatus.Source == "STATION-NETWORK") {
A31MusicModel.Current.CurrentPlayMusicInfoList = new List ();
return;
}
if (A31MusicModel.Current.A31PlayStatus.Source == "AIRPLAY") {
A31MusicModel.Current.CurrentPlayMusicInfoList = new List ();
return;
}
var playString = getCurrentPlayList ();
A31MusicModel.Current.CurrentPlayMusicInfoList = new List ();
var se = System.Security.SecurityElement.FromString (playString);
while (se.Children != null) {
se = se.Children [0] as System.Security.SecurityElement;
}
PlayListName = SecurityElement.FromString (se.Text).SearchForChildByTag ("ListName").Text;
sourceName = SecurityElement.FromString (se.Text).SearchForChildByTag ("ListInfo").SearchForTextOfTag ("SourceName");
foreach (SecurityElement track in SecurityElement.FromString (se.Text).SearchForChildByTag ("Tracks").Children) {
MusicInfo musicInfo = new MusicInfo ();
musicInfo.URL = track.SearchForTextOfTag ("URL").Replace ("&", "&");
var metadata = track.SearchForTextOfTag ("Metadata");
musicInfo.SourceName = track.SearchForTextOfTag ("Source");
if (string.IsNullOrEmpty (metadata)) {
continue;
}
if (A31MusicModel.IsJson (metadata)) {
var qqSong = Newtonsoft.Json.JsonConvert.DeserializeObject (metadata);
musicInfo.Album = qqSong.album;
musicInfo.Title = qqSong.title;
musicInfo.Artist = qqSong.creator;
} else {
metadata = metadata.Replace ("", "").Replace ("&", "&");
var item = SecurityElement.FromString (metadata).SearchForChildByTag ("item");
musicInfo.Title = item.SearchForTextOfTag ("dc:title");
musicInfo.Artist = item.SearchForTextOfTag ("upnp:artist");
musicInfo.Album = item.SearchForTextOfTag ("upnp:album");
musicInfo.Duration = item.SearchForTextOfTag ("res");
musicInfo.AlbumId = item.SearchForTextOfTag ("song:albumid");
}
A31MusicModel.Current.CurrentPlayMusicInfoList.Add (musicInfo);
}
} catch { } finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
listMusic.Musiclist (PlayListName, sourceName, MusicSourcePage);
});
}
});
};
#region 歌曲时间 快,慢进度条
var tempFrameLayout3 = new FrameLayout {
Height = Application.GetRealHeight (130),
Y = Application.GetRealHeight (940 + 100 + 10),
};
middleFrameLayout.AddChidren (tempFrameLayout3);
btnMusicplayTime = new Button {
Width = Application.GetRealWidth (126),
Height = Application.GetRealHeight (126),
X = Application.GetRealWidth (40),
Gravity = Gravity.CenterVertical,
Text = "00:00",
};
tempFrameLayout3.AddChidren (btnMusicplayTime);
btnTotalMusicTime = new Button {
Width = Application.GetRealWidth (126),
Height = Application.GetRealHeight (126),
X = Application.GetRealWidth (830 - 40 - 126),
Gravity = Gravity.CenterVertical,
Text = "00:00",
};
tempFrameLayout3.AddChidren (btnTotalMusicTime);
var layout = new FrameLayout {
X = Application.GetRealWidth (176),
Width = Application.GetRealWidth (478),
Height = Application.GetRealHeight (50),
Gravity = Gravity.CenterVertical,
Radius = (uint)Application.GetRealHeight (25),
};
tempFrameLayout3.AddChidren (layout);
//快进进度条
SeekBarVol = new HorizontalSeekBar {
Width = Application.GetRealWidth (478 - 26),
Height = Application.GetRealHeight (50),
Radius = (uint)Application.GetRealHeight (25),
X = Application.GetRealWidth (13),
Gravity = Gravity.CenterVertical,
ProgressColor = 0xffFE5E00,
SleepTime = 1000,
ThumbRadius = 3,
};
layout.AddChidren (SeekBarVol);
SeekBarVol.MouseUpEventHandler += (sender, e) => {
int totalSecond = (int)(SeekBarVol.Progress * 1.0f / SeekBarVol.Max * int.Parse (A31MusicModel.Current.A31PlayStatus.totlen) / 1000);
//分钟
int Minute = totalSecond / 60;
//秒钟
int Second = totalSecond % 60;
string time = "00" + ":" + (Minute.ToString ().Length < 2 ? "0" + Minute.ToString () : Minute.ToString ()) + ":" + (Second.ToString ().Length < 2 ? "0" + Second.ToString () : Second.ToString ());
A31MusicModel.Current.Seek (time);
A31MusicModel.Current.A31PlayStatus.curpos = (DateTime.Parse (time) - DateTime.Parse ("00:00:00")).TotalMilliseconds.ToString ();
};
#endregion
#region 上,下,暂停/播放
var tempFrameLayout = new FrameLayout {
Height = Application.GetRealHeight (130),
Y = Application.GetRealHeight (1080 + 100 + 10),
};
middleFrameLayout.AddChidren (tempFrameLayout);
prev = new Button {
Width = Application.GetMinRealAverage (126),
Height = Application.GetMinRealAverage (126),
X = Application.GetRealWidth (209),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayPrve.png",
SelectedImagePath = "MusicIcon/PlayPrveSelected.png",
};
tempFrameLayout.AddChidren (prev);
prev.MouseDownEventHandler += (sender, e) => {
prev.IsSelected = true;
A31MusicModel.Current.Previous ();
//sendCommand ("prev");
};
prev.MouseUpEventHandler += (sender, e) => {
prev.IsSelected = false;
};
btnPlay = new Button {
Width = Application.GetMinRealAverage (160),
Height = Application.GetMinRealAverage (127),
X = Application.GetRealWidth (335),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/Playplay.png",
SelectedImagePath = "MusicIcon/playmusicplaySelected.png",
};
tempFrameLayout.AddChidren (btnPlay);
btnPlay.MouseDownEventHandler += (sender, e) => {
if (btnPlay.IsSelected) {
btnPlay.IsSelected = false;
//sendCommand ("pause");
A31MusicModel.Current.Pause ();
A31MusicModel.Current.A31PlayStatus.status = "pause";
} else {
btnPlay.IsSelected = true;
//sendCommand ("resume");
A31MusicModel.Current.Play ();
A31MusicModel.Current.A31PlayStatus.status = "play";
}
};
next = new Button {
Width = Application.GetMinRealAverage (126),
Height = Application.GetMinRealAverage (126),
X = Application.GetRealWidth (495),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayNext.png",
SelectedImagePath = "MusicIcon/PlayNextSelected.png",
};
tempFrameLayout.AddChidren (next);
next.MouseDownEventHandler += (sender, e) => {
next.IsSelected = true;
A31MusicModel.Current.Next ();
//sendCommand ("next");
};
next.MouseUpEventHandler += (sender, e) => {
next.IsSelected = false;
};
#endregion
#region 静音, 音量+,-,
btnMute = new Button {
Width = Application.GetRealWidth (107),
Height = Application.GetRealHeight (127),
X = Application.GetRealWidth (40),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayMute.png",
SelectedImagePath = "MusicIcon/PlayMuteSelected.png",
};
tempFrameLayout.AddChidren (btnMute);
int beforVol = 30;
btnMute.MouseDownEventHandler += (sender, e) => {
btnMute.IsSelected = !btnMute.IsSelected;
if (btnMute.IsSelected) {
A31MusicModel.Current.A31PlayStatus.vol = "0";
//记录之前的音量
beforVol = horizontalSeekBarVol.Progress;
//sendCommand ("vol:0");
A31MusicModel.Current.ControlVolume (0);
} else {
A31MusicModel.Current.A31PlayStatus.vol = beforVol.ToString ();
//sendCommand ("vol:" + beforVol);
A31MusicModel.Current.ControlVolume (beforVol);
}
};
btnMusicvol = new Button {
Width = Application.GetRealWidth (107),
Height = Application.GetRealHeight (127),
X = Application.GetRealWidth (830 - 40 - 107),//680
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayVoice.png",
SelectedImagePath = "MusicIcon/PlayVoiceSelected.png",
};
tempFrameLayout.AddChidren (btnMusicvol);
btnMusicvol.MouseDownEventHandler += (sender, e) => {
Button button = sender as Button;
if (button.IsSelected) {
button.IsSelected = false;
middleFrameLayout.Y += Application.GetRealHeight (100);
} else {
button.IsSelected = true;
middleFrameLayout.Y -= Application.GetRealHeight (100);
}
};
var ProgFrameLayout = new FrameLayout {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (100),
Y = Application.GetRealHeight (1240 + 125),
};
middleFrameLayout.AddChidren (ProgFrameLayout);
var btnMusicvo2 = new Button {
Width = Application.GetRealWidth (107),
Height = Application.GetRealHeight (127),
X = Application.GetRealWidth (40),
Gravity = Gravity.CenterVertical,
UnSelectedImagePath = "MusicIcon/PlayVoice.png",
};
ProgFrameLayout.AddChidren (btnMusicvo2);
var frameLayout = new FrameLayout {
Width = Application.GetRealWidth (600),
Height = Application.GetRealHeight (50),
Gravity = Gravity.CenterVertical,
X = Application.GetRealWidth (160),
};
ProgFrameLayout.AddChidren (frameLayout);
//当前播放的音量
horizontalSeekBarVol = new HorizontalSeekBar {
Width = Application.GetRealWidth (600 - 26),
Height = Application.GetRealHeight (50),
Radius = (uint)Application.GetRealHeight (25),
X = Application.GetRealWidth (13),
Gravity = Gravity.CenterVertical,
ProgressColor = 0xffFE5E00,
Max = 100,
SleepTime = 1000,
ThumbRadius = 9,
};
frameLayout.AddChidren (horizontalSeekBarVol);
horizontalSeekBarVol.ProgressChanged += (sender, e) => {
A31MusicModel.Current.ControlVolume (horizontalSeekBarVol.Progress);
A31MusicModel.Current.A31PlayStatus.vol = horizontalSeekBarVol.Progress.ToString ();
Volume.MusicVolume = horizontalSeekBarVol.Progress;
};
#endregion
Volume.VolumeChange = (volume) =>
{
if (Application.DeviceType == Device.Ios&& A31MusicModel.Current.A31PlayStatus.Source=="BLUETOOTH")
{
return;
}
horizontalSeekBarVol.Progress = volume;
A31MusicModel.Current.ControlVolume (horizontalSeekBarVol.Progress);
A31MusicModel.Current.A31PlayStatus.vol = horizontalSeekBarVol.Progress.ToString ();
};
}
///
/// 获取当前播放的列表
///
string getCurrentPlayList ()
{
StringBuilder getPlayList = new StringBuilder ();
getPlayList.AppendLine ("");
getPlayList.AppendLine ("");
getPlayList.AppendLine ("");
getPlayList.AppendLine ("");
getPlayList.AppendLine ("CurrentQueue");
getPlayList.AppendLine ("");
getPlayList.AppendLine ("");
getPlayList.AppendLine ("");
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#BrowseQueue\"");
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", System.Text.Encoding.UTF8.GetBytes (getPlayList.ToString ()));
return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
} catch { }
return null;
}
void Mode_MouseDownEventHandler (object sender, MouseEventArgs e)
{
Button button = (Button)sender;
switch (A31MusicModel.Current.A31PlayStatus.loop) {
//0列表循环,1单曲循环,2随机播放;
case "0":
A31MusicModel.Current.A31PlayStatus.loop = "1";
button.UnSelectedImagePath = "MusicIcon/playModeDanquplay.png";
button.IsSelected = false;
//new Tip() { Text = Language.StringByID(MyInternationalizationString.singlecycle), Direction = AMPopTipDirection.None }.Show(button);
break;
case "1":
A31MusicModel.Current.A31PlayStatus.loop = "2";
button.UnSelectedImagePath = "MusicIcon/playModesuijiplay.png";
button.IsSelected = false;
//new Tip() { Text = Language.StringByID(MyInternationalizationString.shuffleplay), Direction = AMPopTipDirection.None }.Show(button);
break;
case "2":
A31MusicModel.Current.A31PlayStatus.loop = "0";
button.UnSelectedImagePath = "MusicIcon/playModeliebiaoplay.png";
button.IsSelected = false;
//new Tip() { Text = Language.StringByID(MyInternationalizationString.circulationlisting), Direction = AMPopTipDirection.None }.Show(button);
break;
default:
A31MusicModel.Current.A31PlayStatus.loop = "0";
button.UnSelectedImagePath = "MusicIcon/playModeliebiaoplay.png";
button.IsSelected = false;
//new Tip() { Text = Language.StringByID(MyInternationalizationString.circulationlisting), Direction = AMPopTipDirection.None }.Show(button);
break;
}
sendCommand ("loopmode:" + A31MusicModel.Current.A31PlayStatus.loop);
}
public override void RemoveFromParent ()
{
if (timerUpdateThread != null) {
timerUpdateThread.Abort ();
timerUpdateThread = null;
}
base.RemoveFromParent ();
}
System.Threading.Thread timerUpdateThread;
///
/// 定时更新状态
///
void updateStatus ()
{
string album = null, artist = null;
while (true) {
System.Threading.Thread.Sleep (1000 * 1);
Application.RunOnMainThread (() => {
try {
#region 刷新歌手图片
if (A31MusicModel.Current.A31PlayStatus.Album != album || A31MusicModel.Current.A31PlayStatus.Artist != artist) {
album = A31MusicModel.Current.A31PlayStatus.Album;
artist = A31MusicModel.Current.A31PlayStatus.Artist;
var path = "";
if (Shared.Application.IsPad) {
path = "Pad/" + "MusicImage/AlbumArtistImage_";
} else {
path = "Phone/" + "MusicImage/AlbumArtistImage_";
}
if (Shared.IO.FileUtils.Exists (path + A31MusicModel.Current.A31PlayStatus.Album)) {
portrait.ImagePath = path + A31MusicModel.Current.A31PlayStatus.Album;
} else if (Shared.IO.FileUtils.Exists (path + A31MusicModel.Current.A31PlayStatus.Artist)) {
portrait.ImagePath = path + A31MusicModel.Current.A31PlayStatus.Artist;
} else {
portrait.ImagePath = "MusicIcon/PlayPortrait.png";
System.Threading.Tasks.Task.Run (() => {
var filePath = Shared.IO.FileUtils.DownLoadImageFormBaidu (album, artist);
if (filePath != null) {
Application.RunOnMainThread (() => {
portrait.ImagePath = filePath;
});
}
});
}
}
#endregion
//更新总时间
//总共有多少秒
int totalSecond = int.Parse (A31MusicModel.Current.A31PlayStatus.totlen) / 1000;
//分钟
int totalMusicMinute = totalSecond / 60;
//秒钟
int totalMusicSecond = totalSecond % 60;
string totalTime = (totalMusicMinute.ToString ().Length < 2 ? "0" + totalMusicMinute.ToString () : totalMusicMinute.ToString ()) + ":" + (totalMusicSecond.ToString ().Length < 2 ? "0" + totalMusicSecond.ToString () : totalMusicSecond.ToString ());
btnTotalMusicTime.Text = totalTime;
a31sourceName.Text = A31MusicModel.Current.Name;
switch (A31MusicModel.Current.A31PlayStatus.loop) {
case "1"://单曲顺环
mode.UnSelectedImagePath = "MusicIcon/playModeDanquplay.png";
break;
case "2"://随机播放
mode.UnSelectedImagePath = "MusicIcon/playModesuijiplay.png";
break;
case "0"://列表循环
mode.UnSelectedImagePath = "MusicIcon/playModeliebiaoplay.png";
break;
default:
mode.UnSelectedImagePath = "MusicIcon/playModeliebiaoplay.png";
break;
}
if (A31MusicModel.Current.A31PlayStatus.Source == "RADIO-NETWORK") {
var v = A31MusicModel.Current.CnLoveRadioInfoList.Find ((like) => {
return like.Title == title.Text;
});
if (v != null) {
like.IsSelected = true;
} else {
like.IsSelected = false;
}
} else {
var v = A31MusicModel.Current.LoveMusicInfoList.Find ((like) => {
return like.Title == title.Text;
});
if (v != null) {
like.IsSelected = true;
} else {
like.IsSelected = false;
}
}
if (A31MusicModel.Current.A31PlayStatus.IsMute) {
btnMute.IsSelected = true;
horizontalSeekBarVol.Progress = 0;
} else {
btnMute.IsSelected = false;
horizontalSeekBarVol.Progress = int.Parse (A31MusicModel.Current.A31PlayStatus.vol);
}
//Volume.MusicVolume = horizontalSeekBarVol.Progress;
//当前播放音乐时间
int playSecond = int.Parse (A31MusicModel.Current.A31PlayStatus.curpos) / 1000;// + (int)(DateTime.Now - A31MusicModel.Current.LastDateTime).TotalSeconds;
//currentMusiceA31.musicPalyTime = (playSecond*10).ToString();
//分钟
int playMusicMinute = playSecond / 60;
//秒钟
int playMusicSecond = playSecond % 60;
string playTime = (playMusicMinute.ToString ().Length < 2 ? "0" + playMusicMinute.ToString () : playMusicMinute.ToString ()) + ":" + (playMusicSecond.ToString ().Length < 2 ? "0" + playMusicSecond.ToString () : playMusicSecond.ToString ());
if (A31MusicModel.Current.A31PlayStatus.status == "play") {
btnPlay.IsSelected = true;
//如果在播放,时间就不断变化
btnMusicplayTime.Text = playTime;
if (totalSecond == 0) {
SeekBarVol.Progress = 0;
} else {
SeekBarVol.Progress = (int)(playSecond * 100.0 / totalSecond);//+1
}
} else {
btnPlay.IsSelected = false;
//停止播放
btnMusicplayTime.Text = "00:00";
}
title.Text = (A31MusicModel.Current.A31PlayStatus.Title == null ? "Unkown" : A31MusicModel.Current.A31PlayStatus.Title);
musicartist.Text = (A31MusicModel.Current.A31PlayStatus.Artist == null ? "Unkown" : A31MusicModel.Current.A31PlayStatus.Artist.Trim ());
//更新源的界面
showSourcePage ();
} catch { }
});
}
}
void sendCommand (string coutn)
{
System.Threading.Tasks.Task.Run (() => {
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
try {
byte [] recevieBytes1 = webClient.DownloadData (new Uri ("http://" + A31MusicModel.Current.IPAddress + "/httpapi.asp?command=setPlayerCmd:" + coutn + ""));
} catch (Exception ex) {
//this.IPAddress = ex.Message;
}
});
}
}
}