using System;
|
using System.Collections.Generic;
|
using Newtonsoft.Json.Linq;
|
|
|
namespace Shared
|
{
|
public class SonosMusic
|
{
|
public static List<SonosMusic> SonosMusicList = new List<SonosMusic> ();
|
/// <summary>
|
/// 子网号
|
/// </summary>
|
public byte SubnetID;
|
/// <summary>
|
/// 设备号
|
/// </summary>
|
public byte DeviceID;
|
|
public byte LoopID;
|
|
public DeviceType Type = DeviceType.UnKown;
|
public string sid="";
|
[Newtonsoft.Json.JsonIgnore]
|
public string uid {
|
get {
|
//return (uint)(Convert.ToUInt64 (sid, 16) >> 32);
|
return sid.Substring (0, 8);
|
}
|
}
|
public string name = "";
|
public List<string> sidlist = new List<string> ();
|
public SonosPlayStatus sonosPlayStatus = new SonosPlayStatus ();
|
|
public List<songifon> SonosLovePlayList = new List<songifon> ();
|
public List<listifon> SonosMyList = new List<listifon> ();
|
public List<local> SonosLocalList= new List<local> ();
|
public SonosSlaves slaves= new SonosSlaves ();
|
|
/// <summary>
|
/// 是否允许显示
|
/// </summary>
|
public bool IsCanShow = false;
|
|
/// <summary>
|
/// -1表示从的0表示默认1表示主的
|
/// </summary>
|
public int ServerClientType;
|
|
|
public string CommonLoopID {
|
get {
|
return SubnetID.ToString () + "_" + DeviceID.ToString () + "_" + LoopID.ToString ();
|
}
|
}
|
|
/// <summary>
|
/// event发送控制命令
|
/// </summary>
|
public void eventsend (SonosMusic currentSonosMusic, int Isvalue, int value)
|
{
|
string sid = "";
|
foreach (var str in currentSonosMusic.sidlist) {
|
var sidUlong = Convert.ToUInt64 (str, 16);
|
var property = (byte)((sidUlong >> 16) & 0xFF);
|
if (property == Isvalue) {
|
sid = str;
|
break;
|
}
|
}
|
var jo = new JObject ();
|
var jo1 = new JObject ();
|
var jo2 = new JObject ();
|
|
jo.Add ("sid", sid);
|
jo.Add ("event", jo1);
|
jo1.Add ("type", "music");
|
|
if (Isvalue == 35) {
|
//读取当前播放器状态
|
jo1.Add ("cmd", "getAllCurrentSongInfo");
|
} else if (Isvalue == 34) {
|
//指定列表播放
|
jo1.Add ("cmd", "loadPlayList");
|
jo1.Add ("cmdData", jo2);
|
jo2.Add ("listId", value);
|
} else if (Isvalue == 30) {
|
jo1.Add ("cmd", "setPlayerRelativeVolume");
|
jo1.Add ("cmdData", jo2);
|
jo2.Add ("volumeDelta", value);//-+
|
} else if (Isvalue == 29) {
|
jo1.Add ("cmd", "setPlayerMute");
|
jo1.Add ("cmdData", jo2);
|
if (value == 100) {
|
jo2.Add ("muted", true);//静音
|
} else {
|
jo2.Add ("muted", false);//非静音
|
}
|
} else if (Isvalue == 28) {
|
//正常音量
|
jo1.Add ("cmd", "setPlayerVolume");
|
jo1.Add ("cmdData", jo2);
|
jo2.Add ("volume", value);
|
} else if (Isvalue == 27) {
|
//读取主从信息
|
jo1.Add ("cmd", "getPlayerVolume");
|
} else if (Isvalue == 25) {
|
//获取本地提示音
|
var len = value.ToString ();
|
jo1.Add ("cmd", "loadCloudMusic");
|
jo1.Add ("cmdData", jo2);
|
jo2.Add ("language", "chinese");
|
if (len.Length == 1) {
|
len = "00" + len;
|
} else if (len.Length == 2) {
|
len = "0" + len;
|
}
|
jo2.Add ("id", len);
|
} else if (Isvalue == 15) {
|
jo1.Add ("cmd", "getGroupInfo");
|
}else if (Isvalue == 13) {
|
//读取喜爱列表
|
jo1.Add ("cmd", "getFavorite");
|
} else if (Isvalue == 10) {
|
//快进,退
|
jo1.Add ("cmd", "seek");
|
jo1.Add ("cmdData", jo2);
|
jo2.Add ("positionMillis", value);
|
} else if (Isvalue == 6) {
|
//选曲播放模式
|
jo1.Add ("cmd", "songSelected");
|
jo1.Add ("cmdData", jo2);
|
jo2.Add ("value", value);
|
} else if (Isvalue == 5) {
|
//播放模式
|
jo1.Add ("cmd", "mode");
|
jo1.Add ("cmdData", jo2);
|
jo2.Add ("value", value);
|
} else if (Isvalue == 2) {
|
//上下曲
|
jo1.Add ("cmd", "songStep");
|
jo1.Add ("cmdData", jo2);
|
jo2.Add ("value", value);
|
} else if (Isvalue == 0) {
|
//开关
|
jo1.Add ("cmd", "playback");
|
jo1.Add ("cmdData", jo2);
|
jo2.Add ("value", value);
|
}
|
|
var command = System.Text.Encoding.UTF8.GetBytes (jo.ToString ());
|
//当控制完成时,马上读取状态,会有问题,所以控制后5秒再读取
|
// MyMusic.dateTime = System.DateTime.Now;
|
//发送控制命令
|
Control.ControlBytesSend (Command.SonosControl, SuperGateWay.ScenePage.SubnetID, SuperGateWay.ScenePage.DeviceID, command, SendCount.Zero);
|
}
|
|
public static string SonosMusicImage (string imageUrl,string songname)
|
{
|
|
string imageUrlPath = "SonosMusicImage_";
|
try {
|
var bytes = new Shared.Net.MyWebClient ().DownloadData (new Uri (imageUrl + "@s_1,w_160,h_160"));
|
var filePath = System.IO.Path.Combine (Application.RootPath, imageUrlPath + songname);
|
var fs = new System.IO.FileStream (filePath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
|
fs.Write (bytes, 0, bytes.Length);
|
fs.Flush ();
|
fs.Close ();
|
return filePath;
|
} catch {
|
return null;
|
}
|
|
}
|
|
|
[System.Serializable]
|
public class SonosSlaves
|
{
|
|
public string coordinatorId;
|
public string name;
|
public int playbackState;
|
public List<string> playerIds = new List<string> ();
|
}
|
|
}
|
|
}
|