| | |
| | | using System.Net.Sockets; |
| | | using System.Security; |
| | | using System.Text; |
| | | using HDL_ON.DAL.Server; |
| | | using HDL_ON.Entity; |
| | | using Shared; |
| | | |
| | | namespace HDL_ON.UI.Music |
| | | { |
| | | public class SendMethod |
| | | { |
| | | private static SendMethod m_sendMethod=null; |
| | | public static SendMethod sendMethod |
| | | { |
| | | get |
| | | { |
| | | if (m_sendMethod == null) |
| | | { |
| | | m_sendMethod = new SendMethod(); |
| | | } |
| | | return m_sendMethod; |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | ///搜索A31音乐播放器 |
| | | /// </summary> |
| | |
| | | a31MusicModel.A31PlayStatus.loop = se.SearchForTextOfTag("LoopMode"); |
| | | a31MusicModel.A31PlayStatus.Source = se.SearchForTextOfTag("PlayMedium"); |
| | | a31MusicModel.A31PlayStatus.playSource = se.SearchForTextOfTag("TrackSource"); |
| | | a31MusicModel.A31PlayStatus.TrackURL = se.SearchForTextOfTag("TrackURI").Replace("&", "&amp;"); |
| | | a31MusicModel.A31PlayStatus.TrackURL = se.SearchForTextOfTag("TrackURI").Replace("&", "&amp;"); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | |
| | | /// <param name="volume">Volume.</param> |
| | | public static void ControlVolume(int volume, A31MusicModel a31player) |
| | | { |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | | System.Threading.Tasks.Task.Run(() => { |
| | | A31MusicModel.ProgressDateTime = DateTime.Now; |
| | | try |
| | | { |
| | |
| | | musicInfo.URL = track.SearchForTextOfTag("URL").Replace("&", "&amp;"); |
| | | var metadata = track.SearchForTextOfTag("Metadata").Replace("&", "&"); |
| | | var item = SecurityElement.FromString(metadata).SearchForChildByTag("item"); |
| | | musicInfo.Title = item.SearchForTextOfTag("dc:title").Replace("&", "&amp;"); |
| | | musicInfo.Title = item.SearchForTextOfTag("dc:title").Replace("&", "&amp;"); |
| | | musicInfo.Artist = item.SearchForTextOfTag("upnp:artist").Replace("&", "&amp;"); |
| | | musicInfo.Album = item.SearchForTextOfTag("upnp:album").Replace("&", "&amp;"); |
| | | musicInfo.Duration = item.SearchForTextOfTag("res"); |
| | |
| | | /// <summary> |
| | | /// 获取当前播放的列表 |
| | | /// </summary> |
| | | public static string GetCurrentPlayList(A31MusicModel a31player) |
| | | public static string GetCurrentPlayList(A31MusicModel a31player) |
| | | { |
| | | System.Text.StringBuilder getPlayList = new System.Text.StringBuilder(); |
| | | getPlayList.AppendLine("<?xml version=\"1.0\"encoding=\"utf-8\"?>"); |
| | |
| | | /// <param name="musicInfo">播放音乐</param> |
| | | /// <param name="listName">列表名称</param> |
| | | /// <param name="musicList">推送列表(默认推50首)</param> |
| | | public static void PushList(MusicInfo musicInfo, string listName, List<MusicInfo> musicList, A31MusicModel a31player, string musicSource) |
| | | public static void PushList(MusicInfo musicInfo, string listName, List<MusicInfo> musicList, A31MusicModel a31player,string musicSource) |
| | | { |
| | | |
| | | //最大发送的条数 |
| | |
| | | |
| | | sb.AppendLine("&lt;dc:title&gt;" + tempMusicInfo.Title + "&lt;/dc:title&gt;"); |
| | | sb.AppendLine("&lt;dc:creator&gt;DJ Sanny J&lt;/dc:creator&gt;"); |
| | | if (musicSource == "我的列表") |
| | | { |
| | | if (musicSource== "我的列表") { |
| | | sb.AppendLine("&lt;upnp:artist&gt;" + listName + "&lt;/upnp:artist&gt;"); |
| | | } |
| | | else |
| | | { |
| | | else { |
| | | sb.AppendLine("&lt;upnp:artist&gt;" + tempMusicInfo.Artist + "&lt;/upnp:artist&gt;"); |
| | | } |
| | | sb.AppendLine("&lt;upnp:album&gt;" + tempMusicInfo.Album + "&lt;/upnp:album&gt;"); |
| | |
| | | Play(a31player.IPAddress, a31player.Port, playString.ToString()); |
| | | } |
| | | |
| | | static void SendMusicLists(string ip, int port, string soapAction, string listInfo) |
| | | static void SendMusicLists(string ip, int port, string soapAction, string listInfo) |
| | | { |
| | | System.Net.WebClient webClient = new System.Net.WebClient(); |
| | | webClient.Headers.Add("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#" + soapAction + "\""); |
| | |
| | | byte[] recevieBytes = webClient.UploadData(new Uri("http://" + ip + ":" + port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(listInfo)); |
| | | var s = System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); |
| | | } |
| | | catch (Exception e) |
| | | catch(Exception e) |
| | | { |
| | | var d = e.Message; |
| | | } |
| | | } |
| | | |
| | | static void Play(string ip, int port, string info) |
| | | static void Play(string ip, int port, string info) |
| | | { |
| | | System.Net.WebClient webClient = new System.Net.WebClient(); |
| | | webClient.Headers.Add("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#PlayQueueWithIndex\""); |
| | |
| | | public string creator = string.Empty; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取音乐列表 |
| | | /// </summary> |
| | | public List<Function> GetMusicList |
| | | { |
| | | get |
| | | { |
| | | return FunctionList.List.GetMusicList(); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 发送控制命令 |
| | | /// </summary> |
| | | /// <param name="function">当前设备</param> |
| | | /// <param name="dic">发送控制数据</param> |
| | | public void SendControlCommand(Function function, Dictionary<string, string> dic) |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | | DriverLayer.Control.Ins.SendWriteCommand(function, dic); |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 刷新设备状态 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public void RefreshDeviceStatus(Function music, List<string> functionIds) |
| | | { |
| | | try |
| | | { |
| | | Dictionary<string, object> d = new Dictionary<string, object>(); |
| | | d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id); |
| | | d.Add("deviceIds", functionIds); |
| | | var responsePackNew = RequestServerhomeId(d, NewAPI.Api_Post_RefreshDeviceStatus); |
| | | if (responsePackNew.Code != "0") |
| | | { |
| | | return; |
| | | } |
| | | //数据返序列化为Function对象 |
| | | var str = Newtonsoft.Json.JsonConvert.SerializeObject(responsePackNew.Data.ToString()); |
| | | var function = Newtonsoft.Json.JsonConvert.DeserializeObject<Function>(str); |
| | | if (function == null) |
| | | { |
| | | return; |
| | | } |
| | | music.name = function.name; |
| | | music.sid = function.sid; |
| | | music.spk = function.spk; |
| | | music.status = function.status; |
| | | music.roomIds = function.roomIds; |
| | | music.attributes = function.attributes; |
| | | } |
| | | catch { } |
| | | } |
| | | |
| | | /// <summary> |
| | | ///请求服务器(与住宅有关:例如;homeId) |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ResponsePackNew RequestServerhomeId(object o, string api_Url, int mTimeout = 5) |
| | | { |
| | | var requestJson = HttpUtil.GetSignRequestJson(o); |
| | | return HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout); |
| | | |
| | | } |
| | | } |
| | | } |