/
PlayInterface.cs
298 lines (238 loc) · 9.88 KB
/
PlayInterface.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;//引用System.Data.SqlClient命名空間
namespace Youtube_Media_Player
{
public partial class 播放界面 : Form
{
mainform Mainform;
public 播放界面(mainform Mainform)
{
InitializeComponent();
//歷史紀錄
Mainform.historylistName.Add(Mainform.playlistTitle[Mainform.currentPlay]);
//Mainform.playlistName.Add(Mainform.playlistTitle[Mainform.currentPlay]);
string cn = @"Data Source=(LocalDB)\v11.0;" +
"AttachDbFilename=|DataDirectory|Database1.mdf;" +
"Integrated Security=True";
SqlConnection db = new SqlConnection(cn);//建立連接物件
db.Open(); //使用Open方法開啟和資料庫的連接
SqlCommand cmd = new SqlCommand("INSERT INTO 紀錄(順序,帳號,密碼,個人歌單,歌單ID,歷史紀錄,紀錄ID) VALUES(" +
Mainform.i + ",'" + Mainform.acc + "'" + ",'" + Mainform.psw + "'" + "," + "NULL" + "," + "NULL" +
",'" + Mainform.playlistTitle[Mainform.currentPlay] + "'" + ",'" + Mainform.playlistId[Mainform.currentPlay] + "')", db);
cmd.ExecuteNonQuery();
Mainform.i++;
db.Close(); //使用Close方法關閉和資料庫的連接
}
private void 播放界面_Load(object sender, EventArgs e)
{
//設定timer
timer1.Enabled = true;
}
//
public void setForm(mainform f)
{
Mainform = f;
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text.Equals("播放"))
{
axShockwaveFlash1.Movie = "https://youtube.googleapis.com/v/" + Mainform.nowPlay + "?autoplay=1&version=3&enablejsapi=1";
try
{
string x = axShockwaveFlash1.CallFunction("<invoke name=\"playVideo\" returntype=\"xml\"></invoke>");
}
catch
{
}
button1.Text = "暫停";
}
else
{
try
{
string x = axShockwaveFlash1.CallFunction("<invoke name=\"pauseVideo\" returntype=\"xml\"></invoke>");
}
catch
{
}
button1.Text = "播放";
}
}
//中止
private void button11_Click(object sender, EventArgs e)
{
Mainform.currentPlay = 0;
try
{
axShockwaveFlash1.CallFunction("<invoke name=\"stopVideo\" returntype=\"xml\"></invoke>");
button1.Text = "播放";
}
catch
{
}
Mainform.listenPage.showPlaylist();
}
//下一首
private void button12_Click(object sender, EventArgs e)
{
Mainform.currentPlay++ ; //換下一首
if (Mainform.currentPlay == Mainform.playlistId.Count)
{
Mainform.currentPlay = 0; //超過範圍
}
Mainform.nowPlay = Mainform.playlistId[Mainform.currentPlay]; //存下一首代碼
if (Mainform.nextPlay != "")
{
axShockwaveFlash1.Movie = "https://youtube.googleapis.com/v/" + Mainform.nowPlay + "?autoplay=1&version=3&enablejsapi=1";
try
{
string x = axShockwaveFlash1.CallFunction("<invoke name=\"playVideo\" returntype=\"xml\"></invoke>");
}
catch
{
}
}
Mainform.listenPage.showPlaylist();
//歷史紀錄
Mainform.historylistName.Add(Mainform.playlistTitle[Mainform.currentPlay]);
//Mainform.playlistName.Add(Mainform.playlistTitle[Mainform.currentPlay]);
string cn = @"Data Source=(LocalDB)\v11.0;" +
"AttachDbFilename=|DataDirectory|Database1.mdf;" +
"Integrated Security=True";
SqlConnection db = new SqlConnection(cn);//建立連接物件
db.Open(); //使用Open方法開啟和資料庫的連接
SqlCommand cmd = new SqlCommand("INSERT INTO 紀錄(順序,帳號,密碼,個人歌單,歌單ID,歷史紀錄,紀錄ID) VALUES(" +
Mainform.i + ",'" + Mainform.acc + "'" + ",'" + Mainform.psw + "'" + "," + "NULL" + "," + "NULL" +
",'" + Mainform.playlistTitle[Mainform.currentPlay] + "'" + ",'" + Mainform.playlistId[Mainform.currentPlay] + "')", db);
cmd.ExecuteNonQuery();
Mainform.i++;
db.Close(); //使用Close方法關閉和資料庫的連接
}
//上一首
private void button13_Click(object sender, EventArgs e)
{
Mainform.currentPlay--; //換上一首
if (Mainform.currentPlay<0)
{
Mainform.currentPlay = Mainform.playlistId.Count -1; //超過範圍
}
Mainform.nowPlay = Mainform.playlistId[Mainform.currentPlay]; //存下一首代碼
if (Mainform.prePlay != "")
{
axShockwaveFlash1.Movie = "https://youtube.googleapis.com/v/" + Mainform.nowPlay + "?autoplay=1&version=3&enablejsapi=1";
try
{
string x = axShockwaveFlash1.CallFunction("<invoke name=\"playVideo\" returntype=\"xml\"></invoke>");
}
catch
{
}
}
Mainform.listenPage.showPlaylist();
}
private void button2_Click(object sender, EventArgs e)
{
string x="";
try
{
x = axShockwaveFlash1.CallFunction("<invoke name=\"getPlayerState\" returntype=\"xml\"></invoke>");
// label2.Text = x.Length + x;
if (x.Equals("<number>1</number>"))
{
label2.Text = "撥放中";
}
else
{
label2.Text = x.Length + x;
}
}
catch
{
x = "xxx";
}
// string x = axShockwaveFlash1.CallFunction("<invoke name=\"pauseVideo\" returntype=\"xml\"></invoke>");
//label2.Text = "1+"+x;
}
//監測撥放器狀態
private void timer1_Tick(object sender, EventArgs e)
{
string x = "";
//得到撥放器狀態
try
{
x = axShockwaveFlash1.CallFunction("<invoke name=\"getPlayerState\" returntype=\"xml\"></invoke>");
// label2.Text = x.Length + x;
}
catch
{
x = "xxx";
}
if (x.Equals("<number>1</number>"))
{
label2.Text = "撥放中";
}
else if (x.Equals("<number>0</number>")) //已結束 換下一首
{
label2.Text = "換歌請等待";
Mainform.currentPlay++; //換下一首
if (Mainform.currentPlay == Mainform.playlistId.Count)
{
Mainform.currentPlay = 0; //超過範圍
}
Mainform.nowPlay = Mainform.playlistId[Mainform.currentPlay]; //存下一首代碼
if (Mainform.nextPlay != "")
{
axShockwaveFlash1.Movie = "https://youtube.googleapis.com/v/" + Mainform.nowPlay + "?autoplay=1&version=3&enablejsapi=1";
try
{
string y = axShockwaveFlash1.CallFunction("<invoke name=\"playVideo\" returntype=\"xml\"></invoke>");
}
catch
{
}
}
Mainform.listenPage.showPlaylist();
}
else if (x.Equals("<number>-1</number>")) //未開始
{
label2.Text = "未開始";
}
else if (x.Equals("<number>2</number>")) //已暫停
{
label2.Text = "已暫停";
}
else if (x.Equals("<number>3</number>")) //正在緩衝
{
label2.Text = "正在緩衝";
}
else if (x.Equals("<number>5</number>")) //已插入視頻
{
label2.Text = "已插入視頻";
}
}
private void button3_Click(object sender, EventArgs e)//like 存進歌單資料庫
{
Mainform.playlistName.Add(Mainform.playlistTitle[Mainform.currentPlay]);
string cn = @"Data Source=(LocalDB)\v11.0;" +
"AttachDbFilename=|DataDirectory|Database1.mdf;" +
"Integrated Security=True";
SqlConnection db = new SqlConnection(cn);//建立連接物件
db.Open(); //使用Open方法開啟和資料庫的連接
SqlCommand cmd = new SqlCommand("INSERT INTO 紀錄(順序,帳號,密碼,個人歌單,歌單ID,歷史紀錄,紀錄ID) VALUES(" +
Mainform.i + ",'" + Mainform.acc + "'" + ",'" + Mainform.psw + "'" + ",'" + Mainform.playlistTitle[Mainform.currentPlay] + "'" + ",'" + Mainform.playlistId[Mainform.currentPlay] +
"'" + "," + "NULL" + "," + "NULL" + ")", db);
cmd.ExecuteNonQuery();
Mainform.i++;
db.Close(); //使用Close方法關閉和資料庫的連接
}
}
}