| | |
| | | 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> |
| | |
| | | { |
| | | try |
| | | { |
| | | |
| | | if (a31MusicModel.ServerClientType == 1) |
| | | { |
| | | var result = OpenWeb("http://" + a31MusicModel.IPAddress + "/httpapi.asp?command=multiroom:getSlaveList"); |
| | |
| | | a31MusicModel.A31PlayStatus.loop = se.SearchForTextOfTag("LoopMode"); |
| | | a31MusicModel.A31PlayStatus.Source = se.SearchForTextOfTag("PlayMedium"); |
| | | a31MusicModel.A31PlayStatus.playSource = se.SearchForTextOfTag("TrackSource"); |
| | | a31MusicModel.A31PlayStatus.TrackURL = se.SearchForTextOfTag("TrackURI"); |
| | | a31MusicModel.A31PlayStatus.TrackURL = se.SearchForTextOfTag("TrackURI").Replace("&", "&amp;"); |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.Message); |
| | | } |
| | | finally |
| | | { |
| | | #region 更新其他界面音乐状态 |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | a31MusicModel.trait_on_off.curValue = a31MusicModel.A31PlayStatus.status == "play" ? "on" : "off"; |
| | | //Console.WriteLine($"music : {a31MusicModel.sid} : {a31MusicModel.on_off}"); |
| | | HomePage.UpdataFunctionStates(a31MusicModel); |
| | | foreach (var e in A31MusicModel.A31MusicModelList) |
| | | { |
| | | RoomPage.UpdataStates(a31MusicModel); |
| | | } |
| | | }); |
| | | #endregion |
| | | } |
| | | } |
| | | |
| | |
| | | /// <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 |
| | | { |
| | |
| | | foreach (SecurityElement track in SecurityElement.FromString(se.Text).SearchForChildByTag("Tracks").Children) |
| | | { |
| | | MusicInfo musicInfo = new MusicInfo(); |
| | | musicInfo.URL = track.SearchForTextOfTag("URL"); |
| | | 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"); |
| | | musicInfo.Artist = item.SearchForTextOfTag("upnp:artist"); |
| | | musicInfo.Album = item.SearchForTextOfTag("upnp:album"); |
| | | 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"); |
| | | musicInfo.AlbumId = item.SearchForTextOfTag("song:albumid"); |
| | | musicInfo.AlbumId = item.SearchForTextOfTag("song:albumid").Replace("&", "&amp;"); |
| | | musicInfoList.Add(musicInfo); |
| | | } |
| | | return musicInfoList; |
| | |
| | | /// <returns>读取到的电台组列表信息,读取不到反馈为null</returns> |
| | | public static string ReadRadioList(string url) |
| | | { |
| | | |
| | | WebClient webClient = new WebClient(); |
| | | webClient.Proxy = null; |
| | | webClient.Headers.Add("Content-type", "plain/text; charset=UTF-8"); |
| | |
| | | /// <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\"?>"); |
| | |
| | | return null; |
| | | } |
| | | /// <summary> |
| | | /// 播放音乐命令 |
| | | /// 播放USB音乐命令 |
| | | /// </summary> |
| | | /// <param name="listName">列表名称</param> |
| | | /// <param name="number">播放索引</param> |
| | |
| | | } |
| | | catch { } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 推送播放命令 |
| | | /// </summary> |
| | | /// <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) |
| | | { |
| | | |
| | | //最大发送的条数 |
| | | int maxCount = 50; |
| | | //找出当前点击音乐的索引 |
| | | int statIndex = musicList.FindIndex((obj) => { return obj == musicInfo; }); |
| | | //点击后面还有多少条音乐 |
| | | int count = musicList.Count - statIndex; |
| | | int endIndex = 0; |
| | | if (maxCount < count) |
| | | { |
| | | //如果后面的音乐大于最大数,设置后面数据的最大索引 |
| | | endIndex = statIndex + maxCount - 1; |
| | | } |
| | | else |
| | | { |
| | | //如果后面数据不多,就用总数减去最大条数,得到开始索引 |
| | | statIndex = musicList.Count - maxCount - 1; |
| | | endIndex = musicList.Count - 1; |
| | | } |
| | | //如果开始索引小于0,那就设置为第一条音乐 |
| | | if (statIndex < 0) |
| | | { |
| | | statIndex = 0; |
| | | } |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); |
| | | 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:CreateQueue xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">"); |
| | | sb.AppendLine("<QueueContext><?xml version=\"1.0\"?>"); |
| | | sb.AppendLine("<PlayList>"); |
| | | sb.AppendLine("<ListName>DLNA" + listName + "</ListName>"); |
| | | sb.AppendLine("<ListInfo>"); |
| | | sb.AppendLine("<Radio>0</Radio>");// |
| | | sb.AppendLine("<SourceName>UPnPServer</SourceName>");// |
| | | sb.AppendLine("<MarkSearch>0</MarkSearch>"); |
| | | sb.AppendLine("<TrackNumber>" + (endIndex - statIndex + 1) + "</TrackNumber>"); |
| | | sb.AppendLine("<Quality>0</Quality>"); |
| | | sb.AppendLine("<UpdateTime>5367</UpdateTime>"); |
| | | sb.AppendLine("<LastPlayIndex>2</LastPlayIndex>"); |
| | | sb.AppendLine("<SwitchPageMode>0</SwitchPageMode>"); |
| | | sb.AppendLine("<CurrentPage>0</CurrentPage>"); |
| | | sb.AppendLine("<TotalPages>0</TotalPages>"); |
| | | sb.AppendLine("</ListInfo>"); |
| | | sb.AppendLine("<Tracks>"); |
| | | |
| | | int number = 1; |
| | | |
| | | for (int i = statIndex, Tracknumber = 1; i <= endIndex; i++, Tracknumber++) |
| | | { |
| | | var tempMusicInfo = musicList[i]; |
| | | |
| | | if (musicInfo == tempMusicInfo) |
| | | { |
| | | number = Tracknumber; |
| | | } |
| | | |
| | | if (tempMusicInfo.SourceType == "Local") |
| | | { |
| | | tempMusicInfo.URL = "http://" + new Shared.Net.NetWiFi().IpAddress + ":" + com.hdl.on.Server.Port + "/" + tempMusicInfo.ID; |
| | | } |
| | | |
| | | sb.AppendLine("<Track" + Tracknumber + ">"); |
| | | sb.AppendLine("<URL>" + tempMusicInfo.URL + "</URL>"); |
| | | sb.AppendLine("<Metadata>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;"); |
| | | sb.AppendLine("&lt;DIDL-Lite xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; xmlns:upnp=&quot;urn:schemas-upnp-org:metadata-1-0/upnp/&quot; xmlns:song=&quot;www.wiimu.com/song/&quot; xmlns=&quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&quot;&gt;"); |
| | | sb.AppendLine("&lt;upnp:class&gt;object.item.audioItem.musicTrack&lt;/upnp:class&gt;"); |
| | | sb.AppendLine("&lt;item id=&quot;0&quot;&gt;"); |
| | | sb.AppendLine("&lt;song:subid&gt;&lt;/song:subid&gt;"); |
| | | sb.AppendLine("&lt;song:description&gt;unknown&lt;/song:description&gt;"); |
| | | sb.AppendLine("&lt;song:skiplimit&gt;6&lt;/song:skiplimit&gt;"); |
| | | sb.AppendLine("&lt;song:id&gt;" + tempMusicInfo.ID + "&lt;/song:id&gt;"); |
| | | sb.AppendLine("&lt;song:like&gt;0&lt;/song:like&gt;"); |
| | | sb.AppendLine("&lt;song:singerid&gt;0&lt;/song:singerid&gt;"); |
| | | sb.AppendLine("&lt;song:albumid&gt;" + tempMusicInfo.AlbumId + "&lt;/song:albumid&gt;"); |
| | | |
| | | sb.AppendLine("&lt;res protocolInfo=&quot;http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;&quot; duration=&quot;" + "0:0:0.0" + "&quot;&gt;" + tempMusicInfo.URL + "&lt;/res&gt;"); |
| | | |
| | | 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 == "我的列表") |
| | | { |
| | | sb.AppendLine("&lt;upnp:artist&gt;" + listName + "&lt;/upnp:artist&gt;"); |
| | | } |
| | | 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;"); |
| | | sb.AppendLine("&lt;upnp:albumArtURI&gt;unknown&lt;/upnp:albumArtURI&gt;"); |
| | | sb.AppendLine("&lt;/item&gt;"); |
| | | sb.AppendLine("&lt;/DIDL-Lite&gt;"); |
| | | sb.AppendLine("</Metadata>"); |
| | | sb.AppendLine("<Id>" + tempMusicInfo.ID + "</Id>"); |
| | | sb.AppendLine("<Source>STATION-NETWORK</Source>");//UPnPServer |
| | | sb.AppendLine("<Key>" + tempMusicInfo.URL + "</Key>"); |
| | | sb.AppendLine("</Track" + Tracknumber + ">"); |
| | | } |
| | | sb.AppendLine("</Tracks>"); |
| | | sb.AppendLine("</PlayList>"); |
| | | sb.AppendLine("</QueueContext>"); |
| | | sb.AppendLine("</u:CreateQueue>"); |
| | | sb.AppendLine("</s:Body>"); |
| | | sb.AppendLine("</s:Envelope>"); |
| | | |
| | | SendMusicLists(a31player.IPAddress, a31player.Port, "CreateQueue", sb.ToString()); |
| | | |
| | | StringBuilder playString = new StringBuilder(); |
| | | playString.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); |
| | | playString.AppendLine("<s:Envelope s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">"); |
| | | playString.AppendLine("<s:Body>"); |
| | | playString.AppendLine("<u:PlayQueueWithIndex xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">"); |
| | | playString.AppendLine("<QueueName>DLNA" + listName + "</QueueName>"); |
| | | playString.AppendLine("<Index>" + number + "</Index>"); |
| | | playString.AppendLine("</u:PlayQueueWithIndex>"); |
| | | playString.AppendLine("</s:Body>"); |
| | | playString.AppendLine("</s:Envelope>"); |
| | | |
| | | Play(a31player.IPAddress, a31player.Port, playString.ToString()); |
| | | } |
| | | |
| | | 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 + "\""); |
| | | webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); |
| | | try |
| | | { |
| | | 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) |
| | | { |
| | | var d = e.Message; |
| | | } |
| | | } |
| | | |
| | | 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\""); |
| | | webClient.Headers.Add("CONTENT-TYPE", "text/xml; charset=\"utf-8\""); |
| | | try |
| | | { |
| | | byte[] recevieBytes = webClient.UploadData(new Uri("http://" + ip + ":" + port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes(info)); |
| | | var s = System.Text.Encoding.UTF8.GetString(recevieBytes, 0, recevieBytes.Length); |
| | | } |
| | | catch |
| | | { |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | static System.Threading.Thread thread; |
| | | /// <summary> |
| | |
| | | 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); |
| | | |
| | | } |
| | | } |
| | | } |