1
wxr
2023-03-31 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
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;
    }
 
 
}