using Shared;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Net;
|
using System.Security.Cryptography;
|
|
namespace Shared
|
{
|
[System.Serializable]
|
public class A31MusicModel : MusicModel
|
{
|
public static List<A31MusicModel> A31MusicModelList = new List<A31MusicModel> { };
|
static readonly string a31MusiceModeListFilePath = "A31MusiceModeListFilePath";
|
static A31MusicModel ()
|
{
|
Refresh ();
|
}
|
/// <summary>
|
///保存当前音乐列表
|
/// </summary>
|
public static void Save ()
|
{
|
IO.FileUtils.WriteFileByBytes (a31MusiceModeListFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (A31MusicModelList)));
|
}
|
|
public static void Refresh()
|
{
|
if (null == Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<A31MusicModel>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (a31MusiceModeListFilePath)))) {
|
A31MusicModelList = new List<A31MusicModel> { };
|
//初始化房间列表
|
Save ();
|
} else {
|
A31MusicModelList = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.List<A31MusicModel>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (a31MusiceModeListFilePath)));
|
}
|
if (A31MusicModelList == null) {
|
A31MusicModelList = new List<A31MusicModel> { };
|
}
|
A31MusicModelList.RemoveAll ((obj) => obj == null);
|
}
|
|
public A31MusicModel ()
|
{
|
Type = DeviceType.A31MusicModel;
|
}
|
|
/// <summary>
|
/// IP地址
|
/// </summary>
|
public string IPAddress = "192.168.1.100";
|
|
/// <summary>
|
/// 端口
|
/// </summary>
|
public int Port = 49153;
|
|
|
public bool IsEnd;
|
|
public int A31DeviceType;
|
|
//public string a31Source = "wifi";
|
//public string a31Source = string.Empty;
|
public string UniqueDeviceName = string.Empty;
|
|
/// <summary>
|
/// 当前播放状态
|
/// </summary>
|
public A31PlayStatus A31PlayStatus = new A31PlayStatus ();
|
|
public MusicInfo CurrentMusic = new MusicInfo ();
|
|
/// <summary>
|
///当前播放的列表信息
|
/// </summary>
|
public List<MusicInfo> CurrentPlayMusicInfoList = new List<MusicInfo> ();
|
|
/// <summary>
|
/// 是否允许显示
|
/// </summary>
|
public bool IsCanShow = true;
|
|
/// <summary>
|
/// 是否在线,如果在线就允许读取信息
|
/// </summary>
|
public bool IsOnLine = true;
|
|
/// <summary>
|
/// 喜爱列表
|
/// </summary>
|
public List<MusicInfo> LoveMusicInfoList = new List<MusicInfo> ();
|
|
/// <summary>
|
/// DLNA所有列表
|
/// </summary>
|
public List<MusicInfo> dlnaMusicInfoLists = new List<MusicInfo> ();
|
|
/// <summary>
|
/// 电台所有列表
|
/// </summary>
|
public List<MusicInfo> CnRadioInfoList = new List<MusicInfo> ();
|
|
/// <summary>
|
/// vTuner电台所有列表
|
/// </summary>
|
public List<MusicInfo> vTunerList = new List<MusicInfo> ();
|
|
/// <summary>
|
/// 电台所有列表
|
/// </summary>
|
public List<MusicInfo> CnLoveRadioInfoList = new List<MusicInfo> ();
|
|
/// <summary>
|
/// Pandora电台所有列表
|
/// </summary>
|
public List<MusicInfo> PanRadioInfoList = new List<MusicInfo> ();
|
|
|
/// <summary>
|
/// Tidal喜爱列表
|
/// </summary>
|
public List<MusicInfo> TidalLikelist = new List<MusicInfo> ();
|
|
public List<ListInfo> ListInfos = new List<ListInfo> ();
|
/// <summary>
|
/// 当前的A31音乐播放器
|
/// </summary>
|
public static A31MusicModel Current;
|
|
/// <summary>
|
/// -1表示从的0表示默认1表示主的
|
/// </summary>
|
public int ServerClientType;
|
/// <summary>
|
/// 表示从的播放器IP
|
/// </summary>
|
public string ServerIP = string.Empty;
|
|
|
public Slaves Slave = new Slaves ();
|
|
public static DateTime ProgressDateTime = DateTime.Now;
|
//static System.Threading.Tasks.Task task;
|
//音量列表
|
//static List<int> volumeCommandList = new List<int> ();
|
/// <summary>
|
/// 调节音量
|
/// </summary>
|
/// <param name="volume">Volume.</param>
|
public void ControlVolume (int volume)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
ProgressDateTime = DateTime.Now;
|
try {
|
if (ServerClientType == -1) {
|
new Shared.Net.MyWebClient ().DownloadData (new Uri ("http://" + ServerIP + "/httpapi.asp?command=multiroom:SlaveVolume:" + IPAddress + ":" + volume));
|
} else if (ServerClientType == 1) {
|
new Shared.Net.MyWebClient ().DownloadData (new Uri ("http://" + IPAddress + "/httpapi.asp?command=setPlayerCmd:slave_vol:" + volume));
|
} else {
|
var 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:SetVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\">");
|
sb.AppendLine ("<InstanceID>0</InstanceID>");
|
sb.AppendLine ("<Channel>Master</Channel>");
|
sb.AppendLine ("<DesiredVolume>" + volume + "</DesiredVolume>");
|
sb.AppendLine ("</u:SetVolume>");
|
sb.AppendLine ("</s:Body>");
|
sb.AppendLine ("</s:Envelope>");
|
|
var webClient = new Shared.Net.MyWebClient (5000);
|
webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:RenderingControl:1#SetVolume\"");
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\"");
|
webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendercontrol1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ()));
|
}
|
} catch { }
|
});
|
//lock (volumeCommandList) {
|
// volumeCommandList.Add (volume);
|
//}
|
|
//if (task == null) {
|
// task = System.Threading.Tasks.Task.Run (() => {
|
// while (true) {
|
// try {
|
// System.Threading.Thread.Sleep (100);
|
// int tempVolume = 0;
|
// lock (volumeCommandList) {
|
// if (0 == volumeCommandList.Count) {
|
// continue;
|
// }
|
// tempVolume = volumeCommandList [volumeCommandList.Count - 1];
|
// volumeCommandList.Clear ();
|
// }
|
// ProgressDateTime = DateTime.Now;
|
// if (ServerClientType == -1) {
|
// new Shared.Net.MyWebClient ().DownloadData (new Uri ("http://" + ServerIP + "/httpapi.asp?command=multiroom:SlaveVolume:" + IPAddress + ":" + tempVolume));
|
// } else {
|
// var 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:SetVolume xmlns:u=\"urn:schemas-upnp-org:service:RenderingControl:1\">");
|
// sb.AppendLine ("<InstanceID>0</InstanceID>");
|
// sb.AppendLine ("<Channel>Master</Channel>");
|
// sb.AppendLine ("<DesiredVolume>" + tempVolume + "</DesiredVolume>");
|
// sb.AppendLine ("</u:SetVolume>");
|
// sb.AppendLine ("</s:Body>");
|
// sb.AppendLine ("</s:Envelope>");
|
|
// var webClient = new Shared.Net.MyWebClient (5000);
|
// webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:RenderingControl:1#SetVolume\"");
|
// webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\"");
|
// webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendercontrol1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ()));
|
// }
|
// } catch { }
|
// }
|
// });
|
//}
|
}
|
|
/// <summary>
|
/// 播放
|
/// </summary>
|
/// <param name="volume">Play</param>
|
public void Play ()
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
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:Play xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">");
|
sb.AppendLine ("<InstanceID>0</InstanceID>");
|
sb.AppendLine ("<Speed>1</Speed>");
|
sb.AppendLine ("</u:Play>");
|
sb.AppendLine ("</s:Body>");
|
sb.AppendLine ("</s:Envelope>");
|
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (3000);
|
webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Play\"");
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\"");
|
try {
|
webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ()));
|
} catch { }
|
});
|
}
|
|
public static bool IsJson (string json)
|
{
|
try {
|
if (null == Newtonsoft.Json.Linq.JObject.Parse (json)) {
|
return false;
|
}
|
return true;
|
} catch {
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// 暂停
|
/// </summary>
|
/// <param name="volume">Pause</param>
|
public void Pause ()
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
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:Pause xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">");
|
sb.AppendLine ("<InstanceID>0</InstanceID>");
|
sb.AppendLine ("</u:Pause>");
|
sb.AppendLine ("</s:Body>");
|
sb.AppendLine ("</s:Envelope>");
|
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (3000);
|
webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Pause\"");
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\"");
|
try {
|
webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ()));
|
} catch { }
|
});
|
|
}
|
|
/// <summary>
|
/// 下一曲
|
/// </summary>
|
/// <param name="volume">Pause</param>
|
public void Next ()
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
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:Next xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">");
|
sb.AppendLine ("<InstanceID>0</InstanceID>");
|
sb.AppendLine ("</u:Next>");
|
sb.AppendLine ("</s:Body>");
|
sb.AppendLine ("</s:Envelope>");
|
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (5000);
|
webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Next\"");
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\"");
|
try {
|
webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ()));
|
} catch { }
|
});
|
|
}
|
|
/// <summary>
|
/// 上一曲
|
/// </summary>
|
/// <param name="volume">Pause</param>
|
public void Previous ()
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
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:Previous xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">");
|
sb.AppendLine ("<InstanceID>0</InstanceID>");
|
sb.AppendLine ("</u:Previous>");
|
sb.AppendLine ("</s:Body>");
|
sb.AppendLine ("</s:Envelope>");
|
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (5000);
|
webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Previous\"");
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\"");
|
try {
|
webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ()));
|
} catch { }
|
});
|
|
}
|
|
/// <summary>
|
/// 快进
|
/// </summary>
|
/// <param name="volume">Seek</param>
|
public void Seek (string seekvolume)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
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:Seek xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">");
|
sb.AppendLine ("<InstanceID>0</InstanceID>");
|
sb.AppendLine ("<Unit>REL_TIME</Unit>");
|
sb.AppendLine ("<Target>" + seekvolume + "</Target>");
|
sb.AppendLine ("</u:Seek>");
|
sb.AppendLine ("</s:Body>");
|
sb.AppendLine ("</s:Envelope>");
|
|
Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient (5000);
|
webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-upnp-org:service:AVTransport:1#Seek\"");
|
webClient.Headers.Add ("CONTENT-TYPE", "text/xml; charset=\"utf-8\"");
|
try {
|
webClient.UploadData (new Uri ("http://" + IPAddress + ":" + Port + "/upnp/control/rendertransport1"), "POST", Encoding.UTF8.GetBytes (sb.ToString ()));
|
} catch { }
|
});
|
}
|
}
|
[System.Serializable]
|
/// <summary>
|
/// 自己创建的列表信息
|
/// </summary>
|
public class ListInfo
|
{
|
/// <summary>
|
/// 列表名
|
/// </summary>
|
public string ListName = string.Empty;
|
/// <summary>
|
/// 列表歌曲信息
|
/// </summary>
|
public List<MusicInfo> MusicInfoList = new List<MusicInfo> ();
|
}
|
[System.Serializable]
|
public class TidalMusicInfo : MusicInfo
|
{
|
public MusicInfo MusicInfo;
|
public bool playurl = true;
|
}
|
[System.Serializable]
|
public class Slaves
|
{
|
/// <summary>
|
/// 从播放器值为0
|
/// </summary>
|
public string slaves = "0";
|
public List<Slave> slave_list = new List<Slave> ();
|
}
|
[System.Serializable]
|
public class Slave
|
{
|
public string name = string.Empty;
|
public string mask = string.Empty;
|
public string volume = string.Empty;
|
public string mute = string.Empty;
|
public string channel = string.Empty;
|
public string ip = string.Empty;
|
public string version = string.Empty;
|
public string uuid = string.Empty;
|
}
|
|
|
}
|