using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using Shared.SimpleControl.Phone;
|
using Shared.SimpleControl;
|
using Shared.SimpleControl.R;
|
using Newtonsoft.Json.Linq;
|
namespace Shared.SimpleControl.Phone
|
{
|
public class SonosMyListMusic:FrameLayout
|
{
|
List<Button> buttonList = new List<Button> (100);
|
VerticalScrolViewLayout verticalScrolViewLayout;
|
|
public override void RemoveFromParent ()
|
{
|
base.RemoveFromParent ();
|
|
if (readImageThread != null && readImageThread.IsAlive) {
|
readImageThread.Abort ();
|
}
|
if (updateSelectedMusicThread != null && updateSelectedMusicThread.IsAlive) {
|
updateSelectedMusicThread.Abort ();
|
}
|
}
|
public void Show (SonosMusic sonosMusic,listifon songlist,string name)
|
{
|
|
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 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) => {
|
this.RemoveFromParent ();
|
};
|
|
var musiclist = new Button {
|
Width = Application.GetRealWidth (200),
|
Height = Application.GetRealHeight (150),
|
Text = name,
|
X = Application.GetRealWidth (200),
|
Gravity = Gravity.CenterVertical,
|
};
|
topFrameLayout.AddChidren (musiclist);
|
|
verticalScrolViewLayout = new VerticalScrolViewLayout {
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight (Application.DesignHeight - 126),
|
Y = topFrameLayout.Bottom,
|
BackgroundColor = 0xff2F2F2F,
|
};
|
this.AddChidren (verticalScrolViewLayout);
|
|
|
///进来播放音乐发送命令
|
sonosMusic.eventsend (sonosMusic, 34,songlist.id);
|
buttonList.Clear ();
|
for (int i = 0; i < songlist.songitems.Count; i++) {
|
var songs= songlist.songitems [i];
|
var rowmusic = new RowLayout {
|
Height = Application.GetRealHeight (100),
|
};
|
verticalScrolViewLayout.AddChidren (rowmusic);
|
|
var titleMusic = 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",
|
};
|
rowmusic.AddChidren (titleMusic);
|
|
var path = "MusicImage/AlbumArtistImage_";
|
songs.artist = songs.artist.Split ('/') [0];
|
|
if (Shared.IO.FileUtils.Exists (path + songs.album)) {
|
titleMusic.UnSelectedImagePath = path + songs.album;
|
} else if (Shared.IO.FileUtils.Exists (path + songs.artist)) {
|
titleMusic.UnSelectedImagePath = path + songs.artist;
|
} else {
|
titleMusic.UnSelectedImagePath = "MusicIcon/musicplay1.png";
|
titleMusic.AddTag ("Album", songs.album);
|
titleMusic.AddTag ("Artist", songs.artist);
|
buttonList.Add (titleMusic);
|
}
|
|
var btnMusicName = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (50),
|
Text =songs.name,
|
TextAlignment = TextAlignment.BottomLeft,
|
X = Application.GetRealWidth (100),
|
TextColor = SkinStyle.Current.MusicTextColor,
|
};
|
rowmusic.AddChidren (btnMusicName);
|
|
|
var Artist = new Button {
|
Width = Application.GetRealWidth (400),
|
Height = Application.GetRealHeight (50),
|
Text = songs.artist + "-" + songs.album,
|
TextAlignment = TextAlignment.TopLeft,
|
X = Application.GetRealWidth (100),
|
Y = btnMusicName.Bottom,
|
TextColor = SkinStyle.Current.MusicArtistTextColor,
|
//TextColor = 0x75ffffff,
|
};
|
rowmusic.AddChidren (Artist);
|
|
EventHandler<MouseEventArgs> clicksong = (sender, e) => {
|
rowmusic.BackgroundColor = 0xffFE5E00;
|
System.Threading.Tasks.Task.Run (() => {
|
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 ();
|
var sonosPlay = new SonosPlay { };
|
MainPage.MainFrameLayout.AddChidren (sonosPlay);
|
sonosPlay.Show (sonosMusic);
|
System.Threading.Tasks.Task.Run (() => {
|
sonosMusic.eventsend (sonosMusic, 34,songlist.id);
|
});
|
});
|
});
|
};
|
|
rowmusic.MouseUpEventHandler += clicksong;
|
titleMusic.MouseUpEventHandler += clicksong;
|
Artist.MouseUpEventHandler += clicksong;
|
btnMusicName.MouseUpEventHandler += clicksong;
|
|
}
|
updateSelectedMusic ( sonosMusic);
|
readImage ();
|
|
}
|
|
/// <summary>
|
/// 定时更新当前播放音乐
|
/// </summary>
|
System.Threading.Thread updateSelectedMusicThread;
|
void updateSelectedMusic (SonosMusic sonosMusic)
|
{
|
updateSelectedMusicThread = new System.Threading.Thread (() => {
|
while (this.Parent != null) {
|
System.Threading.Thread.Sleep (1000);
|
Shared.Application.RunOnMainThread (() => {
|
try {
|
for (int i = 0; i < verticalScrolViewLayout.ChildrenCount; i++) {
|
RowLayout view = (RowLayout)verticalScrolViewLayout.GetChildren (i);
|
var songName = (Button)view.GetChildren (1);
|
if (sonosMusic.sonosPlayStatus.songName == songName.Text) {
|
songName.TextColor = 0xffFE5E00;
|
} else {
|
songName.TextColor = SkinStyle.Current.MusicTextColor;
|
}
|
}
|
} catch { }
|
|
});
|
}
|
});
|
updateSelectedMusicThread.Start ();
|
}
|
/// <summary>
|
/// 定时读取图片线程
|
/// </summary>
|
System.Threading.Thread readImageThread;
|
void readImage ()
|
{
|
readImageThread = new System.Threading.Thread (() => {
|
|
for (int i = 0; i < buttonList.Count; i++) {
|
var button = buttonList [i];
|
var album = button.GetTagByKey ("Album");
|
var artist = button.GetTagByKey ("Artist");
|
if (album.ToString () == "" && artist.ToString () == "") {
|
continue;
|
}
|
|
var filePath = Shared.IO.FileUtils.DownLoadImageFormBaidu (album.ToString (), artist.ToString ());
|
if (filePath != null) {
|
Application.RunOnMainThread (() => {
|
button.UnSelectedImagePath = filePath;
|
});
|
}
|
}
|
});
|
readImageThread.Start ();
|
}
|
}
|
}
|