using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using Shared;
|
using Shared.SimpleControl.Phone.Music;
|
using Shared.SimpleControl.R;
|
using Shared.SimpleControl;
|
|
namespace SmartHome.UI.SimpleControl.Phone
|
{
|
/// <summary>
|
/// 收音机播放界面
|
/// </summary>
|
class A31RadioPage : FrameLayout
|
{
|
|
/// <summary>
|
/// 停止/播放
|
/// </summary>
|
Button btnPlay;
|
/// <summary>
|
/// 静音图标
|
/// </summary>
|
Button btnMute;
|
Button btnMusicvol;
|
HorizontalSeekBar horizontalSeekBarVol;
|
/// <summary>
|
/// 频道
|
/// </summary>
|
Button channel;
|
|
/// <summary>
|
/// 频率
|
/// </summary>
|
Button Range;
|
/// <summary>
|
/// 当前界面对象
|
/// </summary>
|
static A31RadioPage currentPage;
|
|
FrameLayout middleFrameLayout = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(1006 + 100),
|
BackgroundImagePath = "MusicIcon/PlayBackgroun.png",
|
};
|
|
A31MusicModel currentMusiceModel;
|
|
public void Show(A31MusicModel a31musiceModel)
|
{
|
if (currentPage != null)
|
{
|
currentPage.RemoveFromParent();
|
}
|
currentPage = this;
|
currentMusiceModel = a31musiceModel;
|
|
//读取当前的音乐状态
|
readStatus();
|
|
AddChidren(new Button()
|
{
|
Height = Application.GetRealHeight(30),
|
BackgroundColor = 0xFF262626,
|
});
|
|
var topFrameLayout = new FrameLayout()
|
{
|
Height = Application.GetRealHeight(100),
|
Y = Application.GetRealHeight(30),
|
BackgroundColor = 0xFF121212,
|
};
|
AddChidren(topFrameLayout);
|
|
var back = new Button
|
{
|
Width = Application.GetMinRealAverage(72),
|
Height = Application.GetMinRealAverage(89),
|
X = Application.GetRealWidth(10),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/PlayBack.png",
|
};
|
topFrameLayout.AddChidren(back);
|
back.MouseDownEventHandler += (sender, o) =>
|
{
|
currentPage = null;
|
//退出界面的时候,从父控件里移除掉
|
RemoveFromParent();
|
};
|
|
topFrameLayout.AddChidren(new Button
|
{
|
Width = Application.GetMinRealAverage(300),
|
Height = Application.GetMinRealAverage(60),
|
Text = currentMusiceModel.Name,
|
Gravity = Gravity.Center,
|
});
|
|
var set = new Button
|
{
|
Width = Application.GetRealWidth(76),
|
Height = Application.GetRealHeight(66),
|
X = Application.GetRealWidth(550),
|
UnSelectedImagePath = "MusicIcon/PlayMusicset.png",
|
Gravity = Gravity.CenterVertical,
|
Tag = currentMusiceModel,
|
};
|
topFrameLayout.AddChidren(set);
|
|
set.MouseDownEventHandler += (sender, e) =>
|
{
|
A31MusicSourcePage a31sourcePage = new A31MusicSourcePage { };
|
MainPage.MainFrameLayout.AddChidren(a31sourcePage);
|
a31sourcePage.Show((A31MusicModel)set.Tag);
|
};
|
|
middleFrameLayout.Y = topFrameLayout.Bottom;
|
AddChidren(middleFrameLayout);
|
topFrameLayout.BringToFront();//隐藏底层
|
|
var sdname = new Button
|
{
|
Width = Application.GetRealWidth(200),
|
Height = Application.GetRealHeight(60),
|
TextID = MyInternationalizationString.MusicFM,
|
TextSize = 15,
|
X = Application.GetRealWidth(230),
|
Y = Application.GetRealHeight(175 - 130)
|
};
|
middleFrameLayout.AddChidren(sdname);
|
|
var audio = new Button
|
{
|
Height = Application.GetRealHeight(248),
|
Y = Application.GetRealHeight(380 - 130),
|
UnSelectedImagePath = "MusicIcon/Radioaudio.png",
|
};
|
middleFrameLayout.AddChidren(audio);
|
|
|
var Radiogarden = new Button
|
{
|
Width = Application.GetRealWidth(319),
|
Height = Application.GetRealHeight(315),
|
X = Application.GetRealWidth(170),
|
Y = Application.GetRealHeight(360 - 130),
|
UnSelectedImagePath = "MusicIcon/Radiogarden.png",
|
};
|
middleFrameLayout.AddChidren(Radiogarden);
|
|
//频率
|
Range = new Button
|
{
|
Width = Application.GetMinRealAverage(350),
|
Height = Application.GetMinRealAverage(80),
|
//Text = "UnKown",
|
TextSize = 25,
|
X = Application.GetRealWidth(145),
|
Y = Application.GetRealHeight(430 - 130),
|
};
|
|
middleFrameLayout.AddChidren(Range);
|
|
var Range1 = new Button
|
{
|
Width = Application.GetMinRealAverage(350),
|
Height = Application.GetMinRealAverage(60),
|
Text = "MHz",
|
TextSize = 20,
|
X = Application.GetRealWidth(150),
|
Y = Application.GetRealHeight(510 - 130),
|
};
|
|
middleFrameLayout.AddChidren(Range1);
|
|
var down = new Button
|
{
|
Width = Application.GetRealWidth(103),
|
Height = Application.GetRealHeight(103),
|
X = Application.GetRealWidth(18),
|
Y = Application.GetRealHeight(839 - 130),
|
UnSelectedImagePath = "MusicIcon/Radiodown.png",
|
SelectedImagePath = "MusicIcon/RadiodownSelected.png",
|
};
|
middleFrameLayout.AddChidren(down);
|
down.MouseDownEventHandler += Down_MouseDownEventHandler;
|
down.MouseUpEventHandler += Down_MouseUpEventHandler;
|
|
//频道
|
channel = new Button
|
{
|
Width = Application.GetMinRealAverage(350),
|
Height = Application.GetMinRealAverage(60),
|
X = Application.GetRealWidth(150),
|
Y = Application.GetRealHeight(847 - 130),
|
};
|
|
middleFrameLayout.AddChidren(channel);
|
|
Button upward = new Button
|
{
|
Width = Application.GetRealWidth(103),
|
Height = Application.GetRealHeight(103),
|
X = Application.GetRealWidth(540),
|
Y = Application.GetRealHeight(827 - 130),
|
UnSelectedImagePath = "MusicIcon/Radioupward.png",
|
SelectedImagePath = "MusicIcon/RadioupwardSelected.png",
|
Tag = currentMusiceModel.Name,
|
};
|
middleFrameLayout.AddChidren(upward);
|
upward.MouseDownEventHandler += Upward_MouseDownEventHandler;
|
upward.MouseUpEventHandler += Upward_MouseUpEventHandler;
|
|
#region 上,下,暂停/播放
|
|
var tempFrameLayout = new FrameLayout
|
{
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight(130),
|
Y = Application.GetRealHeight(960 - 130)
|
};
|
middleFrameLayout.AddChidren(tempFrameLayout);
|
|
var prve = new Button
|
{
|
Width = Application.GetRealWidth(126),
|
Height = Application.GetRealHeight(126),
|
X = Application.GetRealWidth(127),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/PlayPrve.png",
|
SelectedImagePath = "MusicIcon/PlayPrveSelected.png",
|
};
|
|
prve.MouseDownEventHandler += Prve_MouseDownEventHandler;
|
prve.MouseUpEventHandler += Prve_MouseUpEventHandler;
|
tempFrameLayout.AddChidren(prve);
|
|
btnPlay = new Button
|
{
|
Width = Application.GetRealWidth(159),
|
Height = Application.GetRealHeight(127),
|
X = Application.GetRealWidth(260),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/Playplay.png",
|
SelectedImagePath = "MusicIcon/PlayplaySelected.png",
|
};
|
tempFrameLayout.AddChidren(btnPlay);
|
btnPlay.MouseDownEventHandler += Play_MouseDownEventHandler;
|
|
var next = new Button
|
{
|
Width = Application.GetRealWidth(126),
|
Height = Application.GetRealHeight(126),
|
X = Application.GetRealWidth(430),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/PlayNext.png",
|
SelectedImagePath = "MusicIcon/PlayNextSelected.png",
|
};
|
next.MouseDownEventHandler += Next_MouseDownEventHandler;
|
next.MouseUpEventHandler += Next_MouseUpEventHandler;
|
tempFrameLayout.AddChidren(next);
|
#endregion
|
|
#region 音量+,-,静音
|
btnMute = new Button
|
{
|
Width = Application.GetRealWidth(107),
|
Height = Application.GetRealHeight(127),
|
X = Application.GetRealWidth(15),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/PlayMute.png",
|
SelectedImagePath = "MusicIcon/PlayMuteSelected.png",
|
};
|
tempFrameLayout.AddChidren(btnMute);
|
btnMute.MouseDownEventHandler += BtnMute_MouseDownEventHandler;
|
|
btnMusicvol = new Button
|
{
|
Width = Application.GetRealWidth(107),
|
Height = Application.GetRealHeight(127),
|
X = Application.GetRealWidth(540),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/PlayVoice.png",
|
SelectedImagePath = "MusicIcon/PlayVoiceSelected.png",
|
};
|
tempFrameLayout.AddChidren(btnMusicvol);
|
btnMusicvol.MouseDownEventHandler += BtnMusicvol_MouseDownEventHandler;
|
|
var ProgFrameLayout = new FrameLayout
|
{
|
Width = LayoutParams.MatchParent,
|
Height = Application.GetRealHeight(100),
|
Y = Application.GetRealHeight(1120 - 130),
|
};
|
middleFrameLayout.AddChidren(ProgFrameLayout);
|
|
var btnMusicvo2 = new Button
|
{
|
Width = Application.GetRealWidth(107),
|
Height = Application.GetRealHeight(127),
|
X = Application.GetRealWidth(15),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "MusicIcon/PlayVoice.png",
|
};
|
ProgFrameLayout.AddChidren(btnMusicvo2);
|
|
var frameLayout = new FrameLayout
|
{
|
Width = Application.GetRealWidth(490),
|
Height = Application.GetRealHeight(50),
|
Gravity = Gravity.CenterVertical,
|
X = 150,
|
};
|
ProgFrameLayout.AddChidren(frameLayout);
|
|
//当前播放的音量
|
horizontalSeekBarVol = new HorizontalSeekBar
|
{
|
Width = Application.GetRealWidth(490 - 26),
|
Height = Application.GetRealHeight(50),
|
Radius = (uint)Application.GetRealHeight(25),
|
X = Application.GetRealWidth(13),
|
Gravity = Gravity.CenterVertical,
|
Max = 100,
|
BackgroundColor = 0xff525252,
|
};
|
frameLayout.AddChidren(horizontalSeekBarVol);
|
horizontalSeekBarVol.ProgressChanged += HorizontalSeekBarVol_ProgressChanged;
|
#endregion
|
}
|
|
private void Upward_MouseUpEventHandler(object sender, MouseEventArgs e)
|
{
|
Button button = (Button)sender;
|
button.IsSelected = false;
|
}
|
|
private void Upward_MouseDownEventHandler(object sender, MouseEventArgs e)
|
{
|
Button button = (Button)sender;
|
button.IsSelected = true;
|
sendCommand("*S5PREVCHANNELSCAN");
|
}
|
|
private void Down_MouseUpEventHandler(object sender, MouseEventArgs e)
|
{
|
Button button = (Button)sender;
|
button.IsSelected = false;
|
}
|
|
private void Down_MouseDownEventHandler(object sender, MouseEventArgs e)
|
{
|
Button button = (Button)sender;
|
button.IsSelected = true;
|
sendCommand("*S5NEXTCHANNELSCAN");
|
}
|
|
private void Next_MouseDownEventHandler(object sender, MouseEventArgs e)
|
{
|
Button button = (Button)sender;
|
button.IsSelected = true;
|
sendCommand("next");
|
}
|
|
private void Prve_MouseDownEventHandler(object sender, MouseEventArgs e)
|
{
|
Button button = (Button)sender;
|
button.IsSelected = true;
|
sendCommand("prev");
|
}
|
|
private void Prve_MouseUpEventHandler(object sender, MouseEventArgs e)
|
{
|
Button button = (Button)sender;
|
button.IsSelected = false;
|
}
|
|
private void Next_MouseUpEventHandler(object sender, MouseEventArgs e)
|
{
|
Button button = (Button)sender;
|
button.IsSelected = false;
|
}
|
|
|
private void BtnMute_MouseDownEventHandler(object sender, MouseEventArgs e)
|
{
|
|
if (btnMute.IsSelected)
|
{
|
|
btnMute.IsSelected = false;
|
sendCommand("mute:0");
|
}
|
else
|
{
|
|
btnMute.IsSelected = true;
|
sendCommand("mute:1");
|
}
|
|
}
|
|
private void BtnMusicvol_MouseDownEventHandler(object sender, MouseEventArgs 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);
|
}
|
}
|
|
private void HorizontalSeekBarVol_ProgressChanged(object sender, int e)
|
{
|
sendCommand("vol:" + horizontalSeekBarVol.Progress);
|
currentMusiceModel.A31PlayStatus.vol = horizontalSeekBarVol.Progress.ToString();
|
|
}
|
|
private void Play_MouseDownEventHandler(object sender, MouseEventArgs e)
|
{
|
Button button = (Button)sender;
|
if (button.IsSelected)
|
{
|
button.IsSelected = false;
|
sendCommand("pause");
|
currentMusiceModel.A31PlayStatus.status = "pause";
|
}
|
else
|
{
|
button.IsSelected = true;
|
sendCommand("resume");
|
currentMusiceModel.A31PlayStatus.status = "play";
|
}
|
}
|
|
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://" + currentMusiceModel.IPAddress + "/httpapi.asp?command=setPlayerCmd:" + coutn + ""));
|
}
|
catch (Exception ex)
|
{
|
//this.IPAddress = ex.Message;
|
}
|
});
|
}
|
|
/// <summary>
|
/// 读取音乐状态
|
/// </summary>
|
void readStatus()
|
{
|
System.Threading.Tasks.Task.Run(() =>
|
{
|
System.DateTime dateTime = System.DateTime.Now.AddSeconds(-10);
|
|
while (Parent != null)
|
{
|
//等待1秒
|
System.Threading.Thread.Sleep(1000 * 1);
|
|
Application.RunOnMainThread(() =>
|
{
|
try
|
{
|
Range.Text = currentMusiceModel.curMusicListName.Replace("MHz", "");
|
|
channel.Text = currentMusiceModel.curPlayMusicName.Replace(".mp3", "");
|
|
horizontalSeekBarVol.Progress=int.Parse(currentMusiceModel.A31PlayStatus.vol);
|
|
btnMute.IsSelected = currentMusiceModel.CurVol == "0" ? true : false;
|
|
if(currentMusiceModel.PlayStatus == MusicModel.Status.Play)
|
{
|
btnPlay.IsSelected = true;
|
}
|
else
|
{
|
btnPlay.IsSelected = false;
|
}
|
}
|
catch { }
|
});
|
}
|
});
|
}
|
|
}
|
}
|