基于MFC的Media Player播放器的制作(4---功能实现代码)

时间:2021-05-12 05:02:59

|   版权声明:本文为博主原创文章,未经博主允许不得转载。

 

  基于MFC的Media Player播放器的制作(4---功能实现代码)下面附上我整个的播放器功能实现部分的代码,如果有需要整个Project的联系我邮箱:Geore@foxmail.com

基于MFC的Media Player播放器的制作(4---功能实现代码)

PandaPlayerDlg.h

 1 // PandaPlayerDlg.h : header file
2 //
3 //{{AFX_INCLUDES()
4 #include "wmpplayer4.h"
5 #include "wmpcontrols.h"
6 #include "wmpsettings.h"
7 //}}AFX_INCLUDES
8
9 #if !defined(AFX_PANDAPLAYERDLG_H__BD44EB72_E7B8_4CCE_831C_6781A9FDFD2B__INCLUDED_)
10 #define AFX_PANDAPLAYERDLG_H__BD44EB72_E7B8_4CCE_831C_6781A9FDFD2B__INCLUDED_
11
12 #if _MSC_VER > 1000
13 #pragma once
14 #endif // _MSC_VER > 1000
15
16 /////////////////////////////////////////////////////////////////////////////
17 // CPandaPlayerDlg dialog
18
19 class CPandaPlayerDlg : public CDialog
20 {
21 // Construction
22 public:
23 CPandaPlayerDlg(CWnd* pParent = NULL); // standard constructor
24
25 //文件关联对象的变量声明
26 CWMPControls setControl;
27 CWMPSettings setVolume;
28 CSliderCtrl *pSlidCtrl;
29 CSliderCtrl sliderVolume;
30
31
32 // Dialog Data
33 //{{AFX_DATA(CPandaPlayerDlg)
34 enum { IDD = IDD_PANDAPLAYER_DIALOG };
35 CWMPPlayer4 m_ActiveMovie;
36 //}}AFX_DATA
37
38 // ClassWizard generated virtual function overrides
39 //{{AFX_VIRTUAL(CPandaPlayerDlg)
40 protected:
41 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
42 //}}AFX_VIRTUAL
43
44 // Implementation
45 protected:
46 HICON m_hIcon;
47
48 void listDisplay(CString a[]);
49
50 // Generated message map functions
51 //{{AFX_MSG(CPandaPlayerDlg)
52 virtual BOOL OnInitDialog();
53 afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
54 afx_msg void OnPaint();
55 afx_msg HCURSOR OnQueryDragIcon();
56 afx_msg void OnExit();
57 afx_msg void OnFullscreen();
58 afx_msg void OnOpen();
59 afx_msg void OnPlay();
60 afx_msg void OnPause();
61 afx_msg void OnStop();
62 afx_msg void OnGo();
63 afx_msg void OnBack();
64 afx_msg void OnAbout();
65 afx_msg void OnOpenfiles();
66 afx_msg void OnMute();
67 afx_msg void OnLower();
68 afx_msg void OnUpper();
69 afx_msg void OnOutofmemoryVolumeslider();
70 afx_msg void OnNext();
71 afx_msg void OnPrevious();
72 afx_msg void OnLoop();
73 afx_msg void OnOrder();
74 afx_msg void OnRandom();
75 afx_msg void OnTimer(UINT nIDEvent);
76 afx_msg void OnFullscr();
77 afx_msg void OnOnlyplay();
78 //}}AFX_MSG
79 DECLARE_MESSAGE_MAP()
80 };
81
82 //{{AFX_INSERT_LOCATION}}
83 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
84
85 #endif // !defined(AFX_PANDAPLAYERDLG_H__BD44EB72_E7B8_4CCE_831C_6781A9FDFD2B__INCLUDED_)

 


PandaPlayerDlg.cpp

  1 // PandaPlayerDlg.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "PandaPlayer.h"
6 #include "PandaPlayerDlg.h"
7
8 #ifdef _DEBUG
9 #define new DEBUG_NEW
10 #undef THIS_FILE
11 static char THIS_FILE[] = __FILE__;
12 #endif
13
14 //文件数组大小预定义
15 #define N 100
16
17 //全局变量声明
18 static int count = 0;
19 static int times = 0;
20 static int modelFlag = 0;
21 static int flag = 0;
22
23 //0表示
24 static int playStatus = 1;
25 static int pauseStatus = 0;
26 static int stopStatus = 0;
27
28 static int volumeSlider = 0;
29 static long maxVloume = 0;
30 static bool listFlag = true;
31 CString filesPath[N] = {"\0"};
32 time_t t;
33
34
35 /////////////////////////////////////////////////////////////////////////////
36 // CAboutDlg dialog used for App About
37
38 class CAboutDlg : public CDialog
39 {
40 public:
41 CAboutDlg();
42
43 // Dialog Data
44 //{{AFX_DATA(CAboutDlg)
45 enum { IDD = IDD_ABOUTBOX };
46 //}}AFX_DATA
47
48 // ClassWizard generated virtual function overrides
49 //{{AFX_VIRTUAL(CAboutDlg)
50 protected:
51 virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
52 //}}AFX_VIRTUAL
53
54 // Implementation
55 protected:
56 //{{AFX_MSG(CAboutDlg)
57 //}}AFX_MSG
58 DECLARE_MESSAGE_MAP()
59 };
60
61 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
62 {
63 //{{AFX_DATA_INIT(CAboutDlg)
64 //}}AFX_DATA_INIT
65 }
66
67 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
68 {
69 CDialog::DoDataExchange(pDX);
70 //{{AFX_DATA_MAP(CAboutDlg)
71 //}}AFX_DATA_MAP
72 }
73
74 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
75 //{{AFX_MSG_MAP(CAboutDlg)
76 // No message handlers
77 //}}AFX_MSG_MAP
78 END_MESSAGE_MAP()
79
80 /////////////////////////////////////////////////////////////////////////////
81 // CPandaPlayerDlg dialog
82
83 CPandaPlayerDlg::CPandaPlayerDlg(CWnd* pParent /*=NULL*/)
84 : CDialog(CPandaPlayerDlg::IDD, pParent)
85 {
86 //{{AFX_DATA_INIT(CPandaPlayerDlg)
87 // NOTE: the ClassWizard will add member initialization here
88 //}}AFX_DATA_INIT
89 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
90 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
91 }
92
93 void CPandaPlayerDlg::DoDataExchange(CDataExchange* pDX)
94 {
95 CDialog::DoDataExchange(pDX);
96 //{{AFX_DATA_MAP(CPandaPlayerDlg)
97 DDX_Control(pDX, IDC_OCX1, m_ActiveMovie);
98 //}}AFX_DATA_MAP
99 }
100
101 BEGIN_MESSAGE_MAP(CPandaPlayerDlg, CDialog)
102 //{{AFX_MSG_MAP(CPandaPlayerDlg)
103 ON_WM_SYSCOMMAND()
104 ON_WM_PAINT()
105 ON_WM_QUERYDRAGICON()
106 ON_BN_CLICKED(IDC_EXIT, OnExit)
107 ON_BN_CLICKED(IDC_FULLSCREEN, OnFullscreen)
108 ON_BN_CLICKED(IDC_OPEN, OnOpen)
109 ON_BN_CLICKED(IDC_PLAY, OnPlay)
110 ON_BN_CLICKED(IDC_PAUSE, OnPause)
111 ON_BN_CLICKED(IDC_STOP, OnStop)
112 ON_BN_CLICKED(IDC_GO, OnGo)
113 ON_BN_CLICKED(IDC_BACK, OnBack)
114 ON_BN_CLICKED(IDC_ABOUT, OnAbout)
115 ON_BN_CLICKED(IDC_OPENFILES, OnOpenfiles)
116 ON_BN_CLICKED(IDC_MUTE, OnMute)
117 ON_BN_CLICKED(IDC_LOWER, OnLower)
118 ON_BN_CLICKED(IDC_UPPER, OnUpper)
119 ON_NOTIFY(NM_OUTOFMEMORY, IDC_VOLUMESLIDER, OnOutofmemoryVolumeslider)
120 ON_BN_CLICKED(IDC_NEXT, OnNext)
121 ON_BN_CLICKED(IDC_PREVIOUS, OnPrevious)
122 ON_BN_CLICKED(IDC_LOOP, OnLoop)
123 ON_BN_CLICKED(IDC_ORDER, OnOrder)
124 ON_BN_CLICKED(IDC_RANDOM, OnRandom)
125 ON_WM_TIMER()
126 ON_BN_CLICKED(IDC_FULLSCR, OnFullscr)
127 ON_BN_CLICKED(IDC_ONLYPLAY, OnOnlyplay)
128 //}}AFX_MSG_MAP
129 END_MESSAGE_MAP()
130
131 /////////////////////////////////////////////////////////////////////////////
132 // CPandaPlayerDlg message handlers
133
134 BOOL CPandaPlayerDlg::OnInitDialog()
135 {
136 CDialog::OnInitDialog();
137
138 //添加文件关联
139 setControl = static_cast<CWMPControls>(m_ActiveMovie.GetControls());
140 setVolume = m_ActiveMovie.GetSettings();
141
142 //文件列表的初始化的状态为列表处于关闭的状态
143 SetWindowPos(NULL,0,0,542,435,SWP_NOMOVE);
144
145 //初始化音量的滑块条的初始位置
146 //sliderVolume.SetRange(0, 100, true);
147 pSlidCtrl = (CSliderCtrl*)GetDlgItem(IDC_VOLUMESLIDER);
148 pSlidCtrl->SetPos(setVolume.GetVolume());
149
150 //得到初始化时的声音滑块条的位置坐标
151 volumeSlider = pSlidCtrl->GetPos();
152
153 //得到最大的音量值
154 maxVloume = setVolume.GetVolume();// * 2
155
156 //初始化文件数组
157 filesPath[0] = "\0";
158
159 // Add "About..." menu item to system menu.
160
161 // IDM_ABOUTBOX must be in the system command range.
162 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
163 ASSERT(IDM_ABOUTBOX < 0xF000);
164
165 CMenu* pSysMenu = GetSystemMenu(FALSE);
166 if (pSysMenu != NULL)
167 {
168 CString strAboutMenu;
169 strAboutMenu.LoadString(IDS_ABOUTBOX);
170 if (!strAboutMenu.IsEmpty())
171 {
172 pSysMenu->AppendMenu(MF_SEPARATOR);
173 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
174 }
175 }
176
177 // Set the icon for this dialog. The framework does this automatically
178 // when the application's main window is not a dialog
179 SetIcon(m_hIcon, TRUE); // Set big icon
180 SetIcon(m_hIcon, FALSE); // Set small icon
181
182 // TODO: Add extra initialization here
183
184 return TRUE; // return TRUE unless you set the focus to a control
185 }
186
187 void CPandaPlayerDlg::OnSysCommand(UINT nID, LPARAM lParam)
188 {
189 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
190 {
191 CAboutDlg dlgAbout;
192 dlgAbout.DoModal();
193 }
194 else
195 {
196 CDialog::OnSysCommand(nID, lParam);
197 }
198 }
199
200 // If you add a minimize button to your dialog, you will need the code below
201 // to draw the icon. For MFC applications using the document/view model,
202 // this is automatically done for you by the framework.
203
204 void CPandaPlayerDlg::OnPaint()
205 {
206 if (IsIconic())
207 {
208 CPaintDC dc(this); // device context for painting
209
210 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
211
212 // Center icon in client rectangle
213 int cxIcon = GetSystemMetrics(SM_CXICON);
214 int cyIcon = GetSystemMetrics(SM_CYICON);
215 CRect rect;
216 GetClientRect(&rect);
217 int x = (rect.Width() - cxIcon + 1) / 2;
218 int y = (rect.Height() - cyIcon + 1) / 2;
219
220 // Draw the icon
221 dc.DrawIcon(x, y, m_hIcon);
222 }
223 else
224 {
225 CDialog::OnPaint();
226 }
227 }
228
229 // The system calls this to obtain the cursor to display while the user drags
230 // the minimized window.
231 HCURSOR CPandaPlayerDlg::OnQueryDragIcon()
232 {
233 return (HCURSOR) m_hIcon;
234 }
235
236 //打开文件
237 void CPandaPlayerDlg::OnOpen()
238 {
239 // TODO: Add your control notification handler code here
240 char szFileFilter[]="Mp3 File&(*.mp3)|*.mp3|"
241 "Wma File((*.wma)|*.wma|"
242 "Video File(*.dat)|*.dat|"
243 "Wave File(*.wav)|*.wav|"
244 "AVI File(*.avi)|*.avi|"
245 "Movie File(*.mov)|*.mov|"
246 "Media File(*.mmm)|*.mmm|"
247 "Mid File(*.mid *.rmi)|*.mid *.rmi|"
248 "MPEG File(*.mpeg)|*.mpeg|"
249 "All File(*.*)|*.*|| ";//文件类型过滤
250 CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFileFilter);
251 if(dlg.DoModal()==IDOK)
252 {
253 CString strFilePath = dlg.GetPathName();
254 //strFilePath.MakeUpper();
255 filesPath[count++] = strFilePath;
256 m_ActiveMovie.SetUrl(strFilePath);
257 times = count;
258 }
259 }
260
261 //列表播放文件项目的显示
262 void CPandaPlayerDlg::listDisplay(CString fileUrl[])
263 {
264 int index = times;
265 for(int i = 0; i < index; i++)
266 {
267
268 }
269 }
270
271 //播放文件
272 void CPandaPlayerDlg::OnPlay()
273 {
274 // TODO: Add your control notification handler code here
275 setControl.play();
276 //如果是播放状态的时候,播放则为1,暂停和停止均为0
277 playStatus = 1;
278 pauseStatus = 0;
279 stopStatus = 0;
280 }
281
282 //暂停播放
283 void CPandaPlayerDlg::OnPause()
284 {
285 // TODO: Add your control notification handler code here
286 setControl.pause();
287 //如果暂停为真,则暂停为1,播放和停止为0
288 playStatus = 0;
289 pauseStatus = 1;
290 stopStatus = 0;
291 }
292
293 //停止播放
294 void CPandaPlayerDlg::OnStop()
295 {
296 // TODO: Add your control notification handler code here
297 setControl.stop();
298 //如果停止为真,则停止为1,播放和暂停为0
299 playStatus = 0;
300 pauseStatus = 0;
301 stopStatus = 1;
302
303 }
304
305 //快进
306 void CPandaPlayerDlg::OnGo()
307 {
308 // TODO: Add your control notification handler code here
309 double CurrPosition = setControl.GetCurrentPosition();
310 setControl.SetCurrentPosition(CurrPosition+2);
311 }
312
313 //快退
314 void CPandaPlayerDlg::OnBack()
315 {
316 // TODO: Add your control notification handler code here
317 double CurrPosition = setControl.GetCurrentPosition();
318 setControl.SetCurrentPosition(CurrPosition-2);
319 }
320
321 //关于框的调用函数
322 void CPandaPlayerDlg::OnAbout()
323 {
324 // TODO: Add your control notification handler code here
325 CAboutDlg aboutDlg;
326 aboutDlg.DoModal();
327 }
328
329 //文件列表框的弹出和关闭函数
330 void CPandaPlayerDlg::OnOpenfiles()
331 {
332 // TODO: Add your control notification handler code here
333 listFlag=!listFlag;
334 if(listFlag)
335 {
336 //两个数字分别表示宽和高
337 SetWindowPos(NULL,0,0,542,435,SWP_NOMOVE);
338 }
339 else
340 {
341 //文件列表的三个函数在wmpcontrols.h,wmpplaylist.h和wmpmedia.h中
342 //分别是CWMPMedia GetCurrentItem();void SetCurrentItem(LPDISPATCH newValue);void playItem(LPDISPATCH pIWMPMedia);
343 SetWindowPos(NULL,0,0,730,435,SWP_NOMOVE);
344 CString str;
345 }
346 }
347
348 //声音控制的静音函数
349 void CPandaPlayerDlg::OnMute()
350 {
351 // TODO: Add your control notification handler code here
352 if(setVolume.GetMute())
353 {
354 setVolume.SetMute(false);
355 }
356 else
357 {
358 setVolume.SetMute(true);
359 }
360 }
361
362 //降低音量函数
363 void CPandaPlayerDlg::OnLower()
364 {
365 // TODO: Add your control notification handler code here
366 long currVolume = setVolume.GetVolume();
367 if(setVolume.GetMute())
368 {
369 MessageBox(_T("已处于静音状态,不能降低音量"), _T("警告"), MB_OK);
370 }
371 else
372 {
373 setVolume.SetVolume(currVolume-2);
374 }
375 //减少音量之后重新设置音量的滑动条的位置坐标
376 volumeSlider = pSlidCtrl->GetPos();
377 flag = 1;
378 OnOutofmemoryVolumeslider();
379 }
380
381 //音量增加函数
382 void CPandaPlayerDlg::OnUpper()
383 {
384 // TODO: Add your control notification handler code here
385 long currVolume = setVolume.GetVolume();
386 if(setVolume.GetMute())
387 {
388 MessageBox(_T("已处于静音状态,不能增加音量"), _T("警告"), MB_OK);
389 }
390 else
391 {
392 setVolume.SetVolume(currVolume+2);
393 }
394 //增加音量之后重新设置音量的滑动条的位置坐标
395 volumeSlider = pSlidCtrl->GetPos();
396 flag = 2;
397 OnOutofmemoryVolumeslider();
398 }
399
400 //音量滑块条的控制
401 void CPandaPlayerDlg::OnOutofmemoryVolumeslider()
402 {
403 // TODO: Add your control notification handler code here
404 int indexSlider;
405 if(flag == 1 || flag == 2)
406 {
407 pSlidCtrl->SetPos(setVolume.GetVolume());
408 }
409 else
410 {
411 indexSlider = pSlidCtrl->GetPos();
412 //如果indexSlider-volumeSlider>0,说明滑动条往声音调大的范围滑动
413 if(indexSlider-volumeSlider>=0)
414 {
415 setVolume.SetVolume(setVolume.GetVolume()+((indexSlider-volumeSlider)/maxVloume)*2);
416 }
417 else
418 {
419 setVolume.SetVolume(setVolume.GetVolume()-((indexSlider-volumeSlider)/maxVloume)*2);
420 }
421 }
422 }
423
424 //退出函数
425 void CPandaPlayerDlg::OnExit()
426 {
427 // TODO: Add your control notification handler code here
428 setControl.stop();
429 exit(0);
430 }
431
432 //窗口关闭函数
433 void CPandaPlayerDlg::OnFullscreen()
434 {
435 // TODO: Add your control notification handler code here
436 static int flag1 = 0;
437 if(flag1%2==0)
438 {
439 //将状态标志设为暂停的标志(暂停为1, 播放和停止为0)
440 pauseStatus = 1;
441 playStatus = 0;
442 stopStatus = 0;
443 m_ActiveMovie.ShowWindow(false);
444 }
445 else
446 {
447 //将状态标志设为播放的标志(播放为1, 暂停和停止为0)
448 pauseStatus = 0;
449 playStatus = 1;
450 stopStatus = 0;
451 m_ActiveMovie.ShowWindow(true);
452 }
453 flag1++;
454
455 }
456
457 //全屏模式
458 void CPandaPlayerDlg::OnFullscr()
459 {
460 // TODO: Add your control notification handler code here
461 if(m_ActiveMovie.GetFullScreen())
462 {
463 m_ActiveMovie.SetFullScreen(false);
464 }
465 else
466 {
467 m_ActiveMovie.SetFullScreen(true);
468 }
469 }
470
471 //下一曲函数
472 void CPandaPlayerDlg::OnNext()
473 {
474 // TODO: Add your control notification handler code here
475 if(modelFlag==1)
476 {
477 if(filesPath[times+1] == "\0")
478 {
479 times = 0;
480 CString playFiles = filesPath[times++];
481 m_ActiveMovie.SetUrl(playFiles);
482 }
483 else
484 {
485 CString playFiles = filesPath[times++];
486 m_ActiveMovie.SetUrl(playFiles);
487 }
488 }
489 else
490 {
491 if(filesPath[times+1] == "\0")
492 {
493 MessageBox(_T("已到达文件列表尾"),_T("警告"),MB_OK);
494 }
495 else
496 {
497 CString playFiles = filesPath[times++];
498 m_ActiveMovie.SetUrl(playFiles);
499 }
500 }
501 }
502
503 //上一曲函数
504 void CPandaPlayerDlg::OnPrevious()
505 {
506 // TODO: Add your control notification handler code here
507 if(modelFlag==1)
508 {
509 if(times-1 < 0)
510 {
511 times = count;
512 CString playFiles = filesPath[times--];
513 m_ActiveMovie.SetUrl(playFiles);
514 }
515 else
516 {
517 CString playFiles = filesPath[times--];
518 m_ActiveMovie.SetUrl(playFiles);
519 }
520 }
521 else
522 {
523 if(times-1 < 0)
524 {
525 MessageBox(_T("已到达文件列表头"),_T("Warning"),MB_OK);
526 }
527 else
528 {
529 CString playFiles = filesPath[times--];
530 m_ActiveMovie.SetUrl(playFiles);
531 }
532 }
533 }
534
535 //循环播放
536 void CPandaPlayerDlg::OnLoop()
537 {
538 // TODO: Add your control notification handler code here
539 modelFlag = 1;
540 if(filesPath[0] == "\0")
541 {
542 MessageBox(_T("列表无文件!"),_T("警告"),MB_OK);
543 CPandaPlayerDlg::OnOpen();
544 }
545 else
546 {
547 if(setControl.GetCurrentPosition() == 0)
548 {
549 //此时说明播放已经停止,可以进入下一曲播放了
550 if(filesPath[times+1] != "\0")
551 {
552 CString playFiles = filesPath[times++];
553 m_ActiveMovie.SetUrl(playFiles);
554 setControl.SetCurrentPosition(0.01);
555 }
556 else
557 {
558 times = 0;
559 CString playFiles = filesPath[times++];
560 m_ActiveMovie.SetUrl(playFiles);
561 setControl.SetCurrentPosition(0.01);
562 }
563 }
564 else
565 {
566 //通过标志来判断是否进行那种类型的播放状态
567 if(playStatus == 1 && pauseStatus == 0 && stopStatus == 0)
568 setControl.play();
569 else if(pauseStatus == 1 && playStatus == 0 && stopStatus == 0)
570 setControl.pause();
571 else if(stopStatus == 1 && playStatus == 0 && pauseStatus == 0)
572 setControl.stop();
573 else
574 {
575 MessageBox(_T("出现错误"),_T("ERROR"),MB_OK);
576 }
577 }
578 }
579 SetTimer(1,20,NULL);
580 }
581
582 //顺序播放
583 void CPandaPlayerDlg::OnOrder()
584 {
585 // TODO: Add your control notification handler code here
586 modelFlag = 2;
587 if(filesPath[0] == "\0")
588 {
589 MessageBox(_T("列表无文件!"),_T("警告"),MB_OK);
590 CPandaPlayerDlg::OnOpen();
591 }
592 else
593 {
594 if(setControl.GetCurrentPosition() == 0)
595 {
596 //此时说明播放已经停止,可以进入下一曲播放了
597 //首先判断列表是否为空
598 if(filesPath[times+1] != "\0")
599 {
600 CString playFiles = filesPath[times++];
601 m_ActiveMovie.SetUrl(playFiles);
602 setControl.SetCurrentPosition(0.01);
603 }
604 else
605 {
606 MessageBox(_T("已到列表末尾!"),_T("Warning"),MB_OK);
607 CString playFiles = filesPath[0];
608 m_ActiveMovie.SetUrl(playFiles);
609 setControl.SetCurrentPosition(0.01);
610 }
611 }
612 else
613 {
614 if(playStatus == 1 && pauseStatus == 0 && stopStatus == 0)
615 setControl.play();
616 else if(pauseStatus == 1 && playStatus == 0 && stopStatus == 0)
617 setControl.pause();
618 else if(stopStatus == 1 && playStatus == 0 && pauseStatus == 0)
619 setControl.stop();
620 else
621 {
622 MessageBox(_T("出现错误"),_T("ERROR"),MB_OK);
623 }
624 }
625 }
626 SetTimer(2,20,NULL);
627 }
628
629 //随机播放
630 void CPandaPlayerDlg::OnRandom()
631 {
632 // TODO: Add your control notification handler code here
633 modelFlag = 3;
634 if(filesPath[0] == "\0")
635 {
636 MessageBox(_T("列表无文件!"),_T("警告"),MB_OK);
637 CPandaPlayerDlg::OnOpen();
638 }
639 else
640 {
641 if(setControl.GetCurrentPosition() == 0)
642 {
643 //此时说明播放已经停止,可以进入下一曲播放了
644 srand((unsigned)time(&t));
645 int index = rand() % count + 1;
646 CString playFiles = filesPath[index];
647 m_ActiveMovie.SetUrl(playFiles);
648 setControl.SetCurrentPosition(0.01);
649 }
650 else
651 {
652 if(playStatus == 1 && pauseStatus == 0 && stopStatus == 0)
653 setControl.play();
654 else if(pauseStatus == 1 && playStatus == 0 && stopStatus == 0)
655 setControl.pause();
656 else if(stopStatus == 1 && playStatus == 0 && pauseStatus == 0)
657 setControl.stop();
658 else
659 {
660 MessageBox(_T("出现错误"),_T("ERROR"),MB_OK);
661 }
662 }
663 }
664 SetTimer(3,20,NULL);
665 }
666
667
668 //单曲循环播放
669 void CPandaPlayerDlg::OnOnlyplay()
670 {
671 // TODO: Add your control notification handler code here
672 modelFlag = 4;
673 if(filesPath[0] == "\0")
674 {
675 MessageBox(_T("列表无文件!"),_T("警告"),MB_OK);
676 CPandaPlayerDlg::OnOpen();
677 }
678 else
679 {
680 if(setControl.GetCurrentPosition() == 0)
681 {
682 int index = times;
683 CString playFiles = filesPath[index];
684 m_ActiveMovie.SetUrl(playFiles);
685 setControl.SetCurrentPosition(0.01);
686 }
687 else
688 {
689 if(playStatus == 1 && pauseStatus == 0 && stopStatus == 0)
690 setControl.play();
691 else if(pauseStatus == 1 && playStatus == 0 && stopStatus == 0)
692 setControl.pause();
693 else if(stopStatus == 1 && playStatus == 0 && pauseStatus == 0)
694 setControl.stop();
695 else
696 {
697 MessageBox(_T("出现错误"),_T("ERROR"),MB_OK);
698 }
699 }
700 }
701 SetTimer(4,20,NULL);
702 }
703
704
705 //定时器
706 void CPandaPlayerDlg::OnTimer(UINT nIDEvent)
707 {
708 // TODO: Add your message handler code here and/or call default
709
710 switch(nIDEvent)
711 {
712 case 1:
713 {
714 KillTimer(1);
715 OnLoop();
716 break;
717 }
718 case 2:
719 {
720 KillTimer(2);
721 OnOrder();
722 break;
723 }
724 case 3:
725 {
726 KillTimer(3);
727 OnRandom();
728 break;
729 }
730 case 4:
731 {
732 KillTimer(4);
733 OnOnlyplay();
734 break;
735 }
736 }
737
738 CDialog::OnTimer(nIDEvent);
739 }