JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using System;
using System.Collections.Generic;
using System.Text;
using Shared;
using Shared.SimpleControl.R;
 
namespace Shared.SimpleControl.Phone.Music
{
    /// <summary>
    /// SD/USB界面
    /// </summary>
    class A31Usbmusic : FrameLayout
    {
 
        Button seletcedbutton = null;
        bool isExited;
 
        public void show (A31MusicModel a31, List<MusicInfo> musicInfoList)
        {
            this.AddChidren (new Button {
                Height = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            });
 
            var topFrameLayout = new FrameLayout {
                Height = Application.GetRealHeight (90),
                Y = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            };
            AddChidren (topFrameLayout);
 
            var SDlistName = new Button {
                TextID = MyInternationalizationString.SDcard,
                TextColor=SkinStyle.Current.MusicTextColor,
            };
            topFrameLayout.AddChidren (SDlistName);
 
            var hdl = new Button {
                Width = Application.GetRealWidth (154),
                Height = Application.GetRealHeight (90),
                X = Application.GetRealWidth (486),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = MainPage.LogoString,
            };
            topFrameLayout.AddChidren (hdl);
 
            var back = new Button {
                Width = Application.GetRealWidth (82),
                Height = Application.GetRealHeight (89),
                X = Application.GetRealWidth (10),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "MusicIcon/HomepageBack.png",
            };
            topFrameLayout.AddChidren (back);
            back.MouseDownEventHandler += (sender, e) => {
                RemoveFromParent ();
                isExited = true;
            };
 
            var middle = new VerticalScrolViewLayout ();
            middle.Y = topFrameLayout.Bottom;
            middle.Height = Application.GetRealHeight (Application.DesignHeight - 136);
            middle.BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout;
            this.AddChidren (middle);
 
            EventHandler<MouseEventArgs> ddd = (sender, e) => {
                if (seletcedbutton != null) {
                    seletcedbutton.Parent.BackgroundColor = 0xff000000;
                }
                seletcedbutton = sender as Button;
            };
 
            int number = 0;
            List<Button> buttonList = new List<Button> (100);
            if (musicInfoList != null) {
                foreach (var musicInfo in musicInfoList) {
                    //musicInfo.filename = "http://" + "192.168.1.107"+ ":" + "/httpapi.asp?command=setPlayerCmd:playLocalList/media/sda1/music" + musicInfo.Title;
                    number++;
                    var usbrowL = new RowLayout {
                        Height = Application.GetRealHeight (100),
                        LineColor = SkinStyle.Current.MusicRowLayoutLineColor,
                    };
                    middle.AddChidren (usbrowL);
 
                    var title = new Button {
                        Width = Application.GetRealWidth (61),
                        Height = Application.GetRealHeight (61),
                        X = Application.GetRealWidth (20),
                        Gravity = Gravity.CenterVertical,
                        Radius = (uint)Application.GetRealHeight (4),
                        //UnSelectedImagePath = "MusicIcon/musicplay1.png",
                    };
                    usbrowL.AddChidren (title);
 
                    var path = "";
                    if (Shared.Application.IsPad) {
                        path = "Pad/" + "MusicImage/AlbumArtistImage_";
                    } else {
                        path = "Phone/" + "MusicImage/AlbumArtistImage_";
                    }
                    if (Shared.IO.FileUtils.Exists (path + musicInfo.Album)) {
                        title.UnSelectedImagePath = path + musicInfo.Album;
                    } else if (Shared.IO.FileUtils.Exists (path + musicInfo.Artist)) {
                        title.UnSelectedImagePath = path + musicInfo.Artist;
                    } else {
                        title.UnSelectedImagePath = "MusicIcon/musicplay1.png";
                        title.AddTag ("Album", musicInfo.Album);
                        title.AddTag ("Artist", musicInfo.Artist);
                        buttonList.Add (title);
                    }
 
                    var addlikelits = new Button {
                        Width = Application.GetRealWidth (72),
                        Height = Application.GetRealHeight (58),
                        X = Application.GetRealWidth (560),
                        UnSelectedImagePath = "MusicIcon/add.png",
                        Gravity = Gravity.CenterVertical,
                    };
                    usbrowL.AddChidren (addlikelits);
                    addlikelits.MouseUpEventHandler += (sender, e) => {
                        A31MyList A31MyList = new A31MyList ();
                        MainPage.MainFrameLayout.AddChidren (A31MyList);
                        A31MyList.Show (new MusicInfo { SourceType = musicInfo.SourceType, Title = musicInfo.Title, URL = musicInfo.URL, Artist = musicInfo.Artist, Album = musicInfo.Album });
                    };
 
                    var btnMusicName = new Button {
                        Width = Application.GetRealWidth (400),
                        Height = Application.GetRealHeight (50),
                        TextAlignment = TextAlignment.BottomLeft,
                        X = Application.GetRealWidth (100),
                        Text = musicInfo.Title,
                        Tag = number,
                        TextColor = SkinStyle.Current.MusicTextColor,
                    };
                    usbrowL.AddChidren (btnMusicName);
 
                    var artists = new Button {
                        Width = Application.GetRealWidth (400),
                        Height = Application.GetRealHeight (50),
                        TextAlignment = TextAlignment.TopLeft,
                        X = Application.GetRealWidth (100),
                        Y = btnMusicName.Bottom,
                        //TextColor = 0x75ffffff,
                        Text = musicInfo.Artist + "-" + musicInfo.Album,
                        Tag = number,
                        TextColor = SkinStyle.Current.MusicArtistTextColor,
                    };
                    usbrowL.AddChidren (artists);
 
                    EventHandler<MouseEventArgs> musics = (sender, e) => {
                        usbrowL.BackgroundColor = 0xffFE5E00;
                        System.Threading.Tasks.Task.Run (() => {
                            System.Threading.Thread.Sleep (50);
                            Application.RunOnMainThread (() => {
                                //先移除当前控件的前面那个控件 
                                //this.Parent.RemoveAt (this.Parent.ChildrenCount - 3);
                                this.Parent.RemoveAt (this.Parent.ChildrenCount - 2);
                                //移除当前控件界面
                                this.RemoveFromParent ();
                                MainPage.MainFrameLayout.RemoveViewByTag ("A31PlayMusicPage");
                                A31PlayMusicPage a31PlayMusicPage = new A31PlayMusicPage ();
                                MainPage.MainFrameLayout.AddChidren (a31PlayMusicPage);
                                a31PlayMusicPage.Show (new List<MusicInfo> ());
                                a31.A31PlayStatus.Title = btnMusicName.Text;
                                System.Threading.Tasks.Task.Run (() => {
                                    playstrinfg (a31.IPAddress, a31.Port, btnMusicName.Tag);
                                });
                            });
                        });
                    };
 
                    btnMusicName.MouseUpEventHandler += musics;
                    artists.MouseUpEventHandler += musics;
 
                }
            }
 
            System.Threading.Tasks.Task.Run (() => {
                for (int i = 0; i < buttonList.Count; i++) {
                    try {
                        if (isExited) {
                            return;
                        }
                        var button = buttonList [i];
                        var album = button.GetTagByKey ("Album");
                        var artist = button.GetTagByKey ("Artist");
                        if (album == null || artist == null) {
                            continue;
                        }
                        var filePath = Shared.IO.FileUtils.DownLoadImageFormBaidu (album.ToString (), artist.ToString ());
                        if (filePath != null) {
                            Application.RunOnMainThread (() => {
                                button.UnSelectedImagePath = filePath;
                            });
                        }
                    } catch {
                    }
                }
            });
        }
 
 
        void playstrinfg (string ip, int Port, object tag)
        {
            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:PlayQueueWithIndex xmlns:u=\"urn:schemas-wiimu-com:service:PlayQueue:1\">");
            sb.AppendLine ("<QueueName>USBDiskQueue</QueueName>");
            sb.AppendLine ("<Index>" + tag + "</Index>");
            sb.AppendLine ("</u:PlayQueueWithIndex>");
            sb.AppendLine ("</s:Body>");
            sb.AppendLine ("</s:Envelope>");
 
            paly (ip, Port, sb.ToString ());
        }
 
        void paly (string ip, int port, string s)
        {
 
            Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
            webClient.Headers.Add ("SOAPACTION", "\"urn:schemas-wiimu-com:service:PlayQueue:1#PlayQueueWithIndex\"");
            webClient.Headers.Add ("CONTENT-TYPE", "text/xml;charset=\"utf-8\"");
            try {
                byte [] bytes = webClient.UploadData (new Uri ("http://" + ip + ":" + port + "/upnp/control/PlayQueue1"), "POST", System.Text.Encoding.UTF8.GetBytes (s));
                var ab = System.Text.Encoding.UTF8.GetString (bytes, 0, bytes.Length);
            } catch { }
        }
 
 
 
        /// <summary>
        /// 播放歌曲
        /// </summary>
        /// <param name="Tag"></param>
        /// <returns></returns>
        /// 
        string playSong (string ip, object Tag)
        {
            Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
            try {
                byte [] recevieBytes = webClient.DownloadData (new Uri ("http://" + ip + "/httpapi.asp?command=setPlayerCmd:playLocalList" + ":" + Tag));
                return System.Text.Encoding.UTF8.GetString (recevieBytes, 0, recevieBytes.Length);
            } catch {
                return "";
            }
        }
 
        void sendCommand (string ip, string coutn)
        {
            System.Threading.Tasks.Task.Run (() => {
                Shared.Net.MyWebClient webClient = new Shared.Net.MyWebClient ();
                try {
                    byte [] recevieBytes1 = webClient.DownloadData (new Uri ("http://" + ip + "/httpapi.asp?command=setPlayerCmd:" + coutn + ""));
                } catch (Exception ex) {
                    //this.IPAddress = ex.Message;
                }
            });
        }
    }
}