用C編寫音樂播放器_第1頁
用C編寫音樂播放器_第2頁
用C編寫音樂播放器_第3頁
用C編寫音樂播放器_第4頁
用C編寫音樂播放器_第5頁
已閱讀5頁,還剩16頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、目錄一設(shè)計(jì)目標(biāo)二系統(tǒng)設(shè)計(jì)三系統(tǒng)實(shí)現(xiàn)過程1. 程序構(gòu)成2. 創(chuàng)建項(xiàng)目3. 界面設(shè)計(jì)4. 程序設(shè)計(jì)5. 本系統(tǒng)的源代碼四實(shí)驗(yàn)小結(jié)多媒體播放器系統(tǒng)實(shí)現(xiàn)一設(shè)計(jì)目標(biāo)制作一個(gè)具有自己設(shè)計(jì)風(fēng)格的簡單的媒體播放器。要求能隨機(jī)選取要播放的文件,實(shí)現(xiàn)前進(jìn),回退,暫停,循環(huán)播放, 音量大小調(diào)節(jié)等基本功能。能播放多種格式的音頻視頻格式文件,它的功能是能夠選擇一個(gè)有效的以.wav 為后綴的音樂文件,有效的以.mp3為后綴的音樂文件,有效的以.mid 為后綴的音樂文件,有效的以.avi 為后綴的音樂文件,以及CD 文件,在音樂播放的同時(shí),有一個(gè)滑塊來顯示播放的進(jìn)度。實(shí)現(xiàn)其它附加功能如關(guān)閉文件,播放下一首曲目等。界面良好,

2、功能完善二系統(tǒng)設(shè)計(jì)媒體播放器是一個(gè)對(duì)話框窗口,主要由四部分構(gòu)成,概括如下:1. 打開文件:打開要播放的音頻文件并進(jìn)行選擇。2. 播放、循環(huán)播放:對(duì)音頻文件進(jìn)行播放或循環(huán)播放。3. 音量調(diào)節(jié)。4. 關(guān)閉文件。三系統(tǒng)實(shí)現(xiàn)過程1. 程序構(gòu)成媒體播放器主要由以下幾個(gè)類構(gòu)成:CMyplayerApp :多媒體播放器主程序。CMyplayerDlg :用于展現(xiàn)系統(tǒng)運(yùn)行時(shí)的狀態(tài)。CAboutDlg2. 創(chuàng)建項(xiàng)目打開Visual C+6.0的集成開發(fā)環(huán)境,執(zhí)行“文件”“新建”菜單項(xiàng),從彈出的新建對(duì)話框。單擊項(xiàng)目選項(xiàng)卡,在工程類型的列表中選擇MFC AppWizard exe 項(xiàng),在Project name 編

3、輯框中輸入工程名稱myplyer ,在Location 編輯框中輸入保存該工程文件的路徑。單擊OK 按鈕彈出MFC AppWizard-Step 1對(duì)話框,選擇“基本對(duì)話框”,如圖一所示。下面的步驟選取默認(rèn)值。最后在步驟六單擊“完成”按鈕,之后單擊“確定”,完成,打開工作空間。 圖一:3. 界面設(shè)計(jì)在出現(xiàn)的工作界面單擊鼠標(biāo)右鍵,在彈出的菜單選擇其中的Insert ActiveX Control 選項(xiàng),在彈出的對(duì)話框選擇Microsoft Multimedia Control 選項(xiàng),添加一個(gè)MMControl 控件,再依次在對(duì)話框窗口上放置六個(gè)Button 控件,兩個(gè)Slider 控件,一個(gè)編輯

4、框控件,五個(gè)Radio Button 控件,一個(gè)靜態(tài)控件,添加控件后的窗口體如圖二所示。 圖二:窗口的各個(gè)控件的屬性如下:IDC_open打開音樂IDC_play播放IDC_pause暫停IDC_next選擇下一首播放IDC_circle循環(huán)播放IDC_close關(guān)閉IDC_STATIC靜態(tài)控件您所選擇播放的文件類型IDC_RADIO1wav 音頻IDC_RADIO2動(dòng)畫音頻IDC_RADIO3mid 音頻IDC_RADIO4CD 音樂IDC_RADIO5mp3音樂IDC_EDIT14. 程序設(shè)計(jì)給相關(guān)控件添加關(guān)聯(lián)變量,單擊菜單欄的“查看”菜單,選擇“建立類向?qū)А痹趶棾龅膶?duì)話框選擇Member

5、 Variable 標(biāo)簽,給相關(guān)控件添加關(guān)聯(lián)變量,添加完變 量的對(duì)話框如下給各個(gè)按鈕添加相應(yīng)的函數(shù),各個(gè)函數(shù)的功能如下:CMyplayerDlg:Onopen(:打開音樂文件,并選擇要播放的音樂CMyplayerDlg:Onplay(播放選中的音樂CMyplayerDlg:Onpause(暫停音樂CMyplayerDlg:Onclose(關(guān)閉音樂CMyplayerDlg:Onnext(選擇下一首音樂CMyplayerDlg:Oncircle(實(shí)現(xiàn)循環(huán)播放音樂CMyplayerDlg:OnRadio1(播放wav 音頻CMyplayerDlg:OnRadio2(播放動(dòng)畫音頻CMyplayerDl

6、g:OnRadio3(播放mid 音頻CMyplayerDlg:OnRadio4(播放CD 音樂CMyplayerDlg:OnRadio5(播放mp3音樂首先對(duì)界面進(jìn)行初始化,在程序運(yùn)行初期,若沒打開有效的音頻文件,出打開音樂按鈕外,其他按鈕均處于禁用狀態(tài),代碼設(shè)計(jì)如下BOOL CMyplayerDlg:OnInitDialog(CDialog:OnInitDialog(;···/TODO:Add extra initialization herethis->m_pause.EnableWindow(FALSE;this->m_play.EnableW

7、indow(FALSE;this->m_next.EnableWindow(FALSE;this->m_circle.EnableWindow(FALSE;this->m_close.EnableWindow(FALSE;return TRUE; /return TRUE unless you set the focus to a control 運(yùn)行程序,界面如下,打開多媒體文件,給CMyplayerDlg:Onopen(函數(shù)添加相應(yīng)代碼,如下所示:void CMyplayerDlg:Onopen(/TODO:Add your control notification ha

8、ndler code hereCFileDialog OpenDlg(TRUE;switch(this->m_Mediatypethis->m_multimedia.SetDeviceType("WaveAudio"break;this->m_multimedia.SetDeviceType("AviAudio"break;this->m_multimedia.SetDeviceType("Sequencer"break;this->m_multimedia.SetDeviceType("CDA

9、udio"this->m_multimedia.SetCommand("Open"this->m_pause.EnableWindow(TRUE;this->m_play.EnableWindow(TRUE;this->m_next.EnableWindow(TRUE;this->m_circle.EnableWindow(TRUE;this->m_close.EnableWindow(TRUE;if(OpenDlg.DoModal(=IDOKthis->m_multimedia.SetFileName(OpenDlg.G

10、etFileName(;m_edit.SetWindowText(this->m_multimedia.GetFileName(;this->m_multimedia.SetCommand("Open"this->m_pause.EnableWindow(TRUE;this->m_play.EnableWindow(TRUE;this->m_next.EnableWindow(TRUE;this->m_circle.EnableWindow(TRUE;this->m_close.EnableWindow(TRUE; 這樣,程序便可以

11、打開一個(gè)選擇音頻的對(duì)話框,選擇音樂,如下圖所示編寫CMyplayerDlg:Onplay(的代碼,播放選中的音樂,void CMyplayerDlg:Onplay(/TODO:Add your control notification handler code herethis->m_multimedia.SetCommand("Play"運(yùn)行程序,便可對(duì)選中的音樂進(jìn)行播放。編寫CMyplayerDlg:Onpause(的代碼,暫停播放音樂void CMyplayerDlg:Onpause(/TODO:Add your control notification han

12、dler code herethis->m_multimedia.SetCommand("Pause"編寫CMyplayerDlg:Onclose(的代碼,關(guān)閉音樂void CMyplayerDlg:Onclose(/TODO:Add your control notification handler code herethis->m_multimedia.SetCommand("Close"this->m_pause.EnableWindow(FALSE;this->m_play.EnableWindow(FALSE;this-

13、>m_next.EnableWindow(FALSE;this->m_circle.EnableWindow(FALSE;this->m_close.EnableWindow(FALSE;編寫CMyplayerDlg:Onnext(的代碼,實(shí)現(xiàn)選擇下一首音樂void CMyplayerDlg:Onnext(/TODO:Add your control notification handler code herethis->m_multimedia.SetCommand("Next"Onopen(;this->m_multimedia.SetCo

14、mmand("Play"編寫CMyplayerDlg:Oncircle(的代碼,實(shí)現(xiàn)循環(huán)播放音樂void CMyplayerDlg:Oncircle(/TODO:Add your control notification handler code hereint i;for(i=0;i<50;i+this->m_multimedia.SetCommand("Prev"this->m_multimedia.SetCommand("Play"最后,程序運(yùn)行結(jié)果的界面如下: 5. 本系統(tǒng)的源代碼如下/myplayerDlg

15、.cpp :implementation file/#include"stdafx.h"#include"myplayer.h"#include"myplayerDlg.h"#ifdef_DEBUG#definenew DEBUG_NEW#undefTHIS_FILEstatic char THIS_FILE=_FILE_;#endif/CAboutDlg dialog used for App Aboutclass CAboutDlg :public CDialogpublic:CAboutDlg(;/Dialog Data/AFX

16、_DATA(CAboutDlgenum IDD =IDD_ABOUTBOX;/AFX_DATA/ClassWizard generated virtual function overrides/AFX_VIRTUAL(CAboutDlgprotected:virtual void DoDataExchange(CDataExchange*pDX;/AFX_VIRTUAL/Implementationprotected:/AFX_MSG(CAboutDlg/AFX_MSGDECLARE_MESSAGE_MAP(;CAboutDlg:CAboutDlg(:CDialog(CAboutDlg:IDD

17、/AFX_DATA_INIT(CAboutDlg/AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange*pDXCDialog:DoDataExchange(pDX;/AFX_DATA_MAP(CAboutDlg/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg,CDialog/AFX_MSG_MAP(CAboutDlg/No message handlers/AFX_MSG_MAPEND_MESSAGE_MAP(/CMyplayerDlg dialog /DDX/DDVsupportCMyplayerDl

18、g:CMyplayerDlg(CWnd*pParent /*=NULL*/:CDialog(CMyplayerDlg:IDD,pParent/AFX_DATA_INIT(CMyplayerDlgm_voice=0;/AFX_DATA_INIT/Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon=AfxGetApp(->LoadIcon(IDR_MAINFRAME;void CMyplayerDlg:DoDataExchange(CDataExchange*pDX CDialog:DoDa

19、taExchange(pDX;/AFX_DATA_MAP(CMyplayerDlgDDX_Control(pDX,IDC_EDIT1,m_edit;DDX_Control(pDX,IDC_circle,m_circle;DDX_Control(pDX,IDC_SLIDER1,m_slider;DDX_Control(pDX,IDC_play,m_play;DDX_Control(pDX,IDC_pause,m_pause;DDX_Control(pDX,IDC_open,m_open;DDX_Control(pDX,IDC_next,m_next;DDX_Control(pDX,IDC_clo

20、se,m_close;DDX_Slider(pDX,IDC_SLIDER2,m_voice;DDX_Control(pDX,IDC_MMCONTROL1,m_multimedia;/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CMyplayerDlg,CDialog/AFX_MSG_MAP(CMyplayerDlgON_WM_SYSCOMMAND(ON_WM_PAINT(ON_WM_QUERYDRAGICON(ON_BN_CLICKED(IDC_open,OnopenON_BN_CLICKED(IDC_RADIO1,OnRadio1ON_BN_CLICKED(IDC_RADIO

21、3,OnRadio3ON_BN_CLICKED(IDC_RADIO2,OnRadio2ON_BN_CLICKED(IDC_RADIO4,OnRadio4ON_BN_CLICKED(IDC_play,OnplayON_BN_CLICKED(IDC_pause,OnpauseON_BN_CLICKED(IDC_close,OncloseON_BN_CLICKED(IDC_next,OnnextON_BN_CLICKED(IDC_circle,Oncircle/AFX_MSG_MAPEND_MESSAGE_MAP(/CMyplayerDlg message handlersBOOL CMyplaye

22、rDlg:OnInitDialog(CDialog:OnInitDialog(;/Add "About." menu item to system menu./IDM_ABOUTBOXmust be in the system command range.ASSERT(IDM_ABOUTBOX&0xFFF0 =IDM_ABOUTBOX;ASSERT(IDM_ABOUTBOX<0xF000;CMenu*pSysMenu =GetSystemMenu(FALSE;if (pSysMenu!=NULLCString strAboutMenu;strAboutMenu

23、.LoadString(IDS_ABOUTBOX;if (!strAboutMenu.IsEmpty(pSysMenu->AppendMenu(MF_SEPARATOR;pSysMenu->AppendMenu(MF_STRING,strAboutMenu;IDM_ABOUTBOX,/Set the icon for this dialog. The framework does this automatically /when the application's main window is not a dialogSetIcon(m_hIcon,TRUE; /Set b

24、ig iconSetIcon(m_hIcon,FALSE; /Set small icon/TODO:Add extra initialization herethis->m_pause.EnableWindow(FALSE;this->m_play.EnableWindow(FALSE;this->m_next.EnableWindow(FALSE;this->m_circle.EnableWindow(FALSE;this->m_close.EnableWindow(FALSE;return TRUE; /return TRUE unless you set

25、the focus to a control void CMyplayerDlg:OnSysCommand(UINTnID, LPARAM lParam if (nID&0xFFF0 =IDM_ABOUTBOXCAboutDlg dlgAbout;dlgAbout.DoModal(;elseCDialog:OnSysCommand(nID,lParam; / If you add a minimize button to your dialog, you will need the code below / to draw the icon. For MFC applications

26、using the document/view model, / this is automatically done for you by the framework. void CMyplayerDlg:OnPaint( if (IsIconic( CPaintDC dc(this; / device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM dc.GetSafeHdc(, 0; / Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_

27、CXICON; int cyIcon = GetSystemMetrics(SM_CYICON; CRect rect; GetClientRect(&rect; int x = (rect.Width( - cxIcon + 1 / 2; int y = (rect.Height( - cyIcon + 1 / 2; / Draw the icon dc.DrawIcon(x, y, m_hIcon; else CDialog:OnPaint(; / The system calls this to obtain the cursor to display while the use

28、r drags / the minimized window. HCURSOR CMyplayerDlg:OnQueryDragIcon( return (HCURSOR m_hIcon; void CMyplayerDlg:Onopen( / TODO: Add your control notification handler code here CFileDialog OpenDlg(TRUE; switch(this->m_Mediatype void CMyplayerDlg:OnRadio2( / TODO: Add your control notification han

29、dler code here m_Mediatype=3; void CMyplayerDlg:OnRadio4( / TODO: Add your control notification handler code here m_Mediatype=4; void CMyplayerDlg:Onplay( / TODO: Add your control notification handler code here this->m_multimedia.SetCommand("Play" BEGIN_EVENTSINK_MAP(CMyplayerDlg, CDial

30、og /AFX_EVENTSINK_MAP(CMyplayerDlg ON_EVENT(CMyplayerDlg, IDC_MMCONTROL1, 28 /* StatusUpdate */, OnStatusUpdateMmcontrol1, VTS_NONE /AFX_EVENTSINK_MAP END_EVENTSINK_MAP( void CMyplayerDlg:OnStatusUpdateMmcontrol1( / TODO: Add your control notification handler code here this->m_slider.SetRange(0,this->m_multimedia.GetLength(,TRUE; this->m_slider.SetPos(this->m_multimedia.GetPosition(; void CMyplayerDlg:Onpause( / TODO: Add your control notification han

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論