




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验2 简单音频播放器程序实现1. 上机实验报告二课程名称:多媒体技术班级:数媒*班实验日期:2014.3.31-4.11小组成员:指导教师:实验序号:02实验成绩:一、简单音频播放器程序实现二、实验目的及要求1、掌握使用DirectSound实现音频播放程序的方法;2、掌握创建缓冲区的方法;3、学会播放音频数据的方法;3、了解RIFF文件格式,学会读取WAV文件的方法;4、开发一个简单的基于MFC框架的音频播放器。三、实验环境本次上机实践所使用的平台和相关软件VS2012MFCwin7四、实验内容用MFC设计具有一般能播放*.mp3,*.wma,*.mdi,*.wav,*.avi,*.dat等文件,还有具有播放、暂停、停止、音量调节等功能。1、点击“打开”,添加播放资源2、单击“播放”,开始播放3、点击“暂停”,暂停播放;之后点击“恢复”,播放器继续播放4、单击“终止”,音乐播放停止5、滑动音量滑块调节音量大小五、调试过程及实验结果本次作业参考了优酷上的指导视频,然后仿照编写的。 在完成此次大作业的过程中遇到了很多问题,首先音量控制就是一个难点,最初完成的版本可以运行但音量无法控制,后来添加了一个函数解决问题:void CMUSIC_PLAYER_100511217Dlg:OnCustomdrawSlider(NMHDR* pNMHDR, LRESULT* pResult) UpdateData(true); m_vol=m_slider.GetPos()/10;SetVolumn(m_slider.GetPos();UpdateData(false);*pResult = 0;最终成果:六、总结过完成这个简易的音乐播放器,掌握到了MFC编程的基本方法,使自己的编程能力得到进一步的提高,学会使用DirectSound实现音频播放程序的方法。7、 附录player.cpp/ player.cpp : Defines the class behaviors for the application./#include stdafx.h#include player.h#include playerDlg.h#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CMyAppBEGIN_MESSAGE_MAP(CMyApp, CWinApp)/AFX_MSG_MAP(CMyApp)/ NOTE - the ClassWizard will add and remove mapping macros here./ DO NOT EDIT what you see in these blocks of generated code!/AFX_MSGON_COMMAND(ID_HELP, CWinApp:OnHelp)END_MESSAGE_MAP()/ CMyApp constructionCMyApp:CMyApp()/ TODO: add construction code here,/ Place all significant initialization in InitInstance/ The one and only CMyApp objectCMyApp theApp;/ CMyApp initializationBOOL CMyApp:InitInstance()AfxEnableControlContainer();/ Standard initialization/ If you are not using these features and wish to reduce the size/ of your final executable, you should remove from the following/ the specific initialization routines you do not need.#ifdef _AFXDLLEnable3dControls();/ Call this when using MFC in a shared DLL#elseEnable3dControlsStatic();/ Call this when linking to MFC statically#endifCMyDlg dlg;m_pMainWnd = &dlg;int nResponse = dlg.DoModal();if (nResponse = IDOK)/ TODO: Place code here to handle when the dialog is/ dismissed with OKelse if (nResponse = IDCANCEL)/ TODO: Place code here to handle when the dialog is/ dismissed with Cancel/ Since the dialog has been closed, return FALSE so that we exit the/ application, rather than start the applications message pump.return FALSE;playerDlg.cpp/ playerDlg.cpp : implementation file/#include stdafx.h#include player.h#include playerDlg.h#includeMmsystem.h#includeDigitalv.h#pragma comment(lib,Winmm.lib)#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endifHWND m_hWnd;MCI_OPEN_PARMS mciopenparms;DWORD ItemLength,ItemTo;DWORD item;/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogpublic:CAboutDlg();/ Dialog Data/AFX_DATA(CAboutDlg)enum IDD = IDD_ABOUTBOX ;/AFX_DATA/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CAboutDlg)protected:virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV support/AFX_VIRTUAL/ Implementationprotected:/AFX_MSG(CAboutDlg)/AFX_MSGDECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD)/AFX_DATA_INIT(CAboutDlg)/AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange* pDX)CDialog: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()/ CMyDlg dialogCMyDlg:CMyDlg(CWnd* pParent /*=NULL*/): CDialog(CMyDlg:IDD, pParent)/AFX_DATA_INIT(CMyDlg)m_int = 0;/AFX_DATA_INIT/ Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()-LoadIcon(IDI_ICON1);void CMyDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CMyDlg)DDX_Control(pDX, IDC_volslider, m_controlvol);DDX_Control(pDX, IDC_playslider, m_process);DDX_Text(pDX, IDC_EDIT1, m_int);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CMyDlg, CDialog)/AFX_MSG_MAP(CMyDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_about, Onabout)ON_BN_CLICKED(IDC_exit, Onexit)ON_BN_CLICKED(IDC_play, Onplay)ON_WM_TIMER()ON_BN_CLICKED(IDC_filechoice, Onfilechoice)ON_NOTIFY(NM_CUSTOMDRAW, IDC_playslider, OnCustomdrawplayslider)ON_BN_CLICKED(IDC_pause, Onpause)ON_BN_CLICKED(IDC_stop, Onstop)ON_NOTIFY(NM_CUSTOMDRAW, IDC_volslider, OnCustomdrawvolslider)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CMyDlg message handlersBOOL CMyDlg:OnInitDialog()CDialog:OnInitDialog();/ Add About. menu item to system menu./ IDM_ABOUTBOX must be in the system command range.ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ Set the icon for this dialog. The framework does this automatically/ when the applications main window is not a dialogSetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);m_controlvol.SetRange(0,1500);m_controlvol.SetPos(750);GetDlgItem(IDC_play)-EnableWindow(false);GetDlgItem(IDC_pause)-EnableWindow(false);GetDlgItem(IDC_stop)-EnableWindow(false);/ Set small icon/ TODO: Add extra initialization herereturn TRUE; / return TRUE unless you set the focus to a controlvoid CMyDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg 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 using the document/view model,/ this is automatically done for you by the framework.void CMyDlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangleint cxIcon = GetSystemMetrics(SM_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 icondc.DrawIcon(x, y, m_hIcon);elseCDialog:OnPaint();/ The system calls this to obtain the cursor to display while the user drags/ the minimized window.HCURSOR CMyDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;DWORD GetLength(DWORD dwitem) /根据参数获取媒体文件信息/*/接受传入的命令参数,命令参数如下: MCI_STATUS_LENGTH获取总播放时间,MCI_STATUS_POSITION获取当前已播放时间: */MCI_STATUS_PARMS mcistatusparms; mcistatusparms.dwCallback=(DWORD)m_hWnd; mcistatusparms.dwItem=dwitem; mcistatusparms.dwReturn=0; /返回值初始化mciSendCommand(mciopenparms.wDeviceID,MCI_STATUS,MCI_STATUS_ITEM,(DWORD)&mcistatusparms);return mcistatusparms.dwReturn;void open(CString strnamepath)mciSendCommand(mciopenparms.wDeviceID,MCI_CLOSE,0,0);mciopenparms.lpstrElementName=strnamepath;DWORD dwReturn; if(dwReturn=mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT|MCI_WAIT,(DWORD)(LPVOID)&mciopenparms)/打开失败,显示警告,并存储错误信息char buffer256;mciGetErrorString(dwReturn,buffer,256);MessageBox(m_hWnd,buffer,出错警告!,MB_ICONHAND|MB_ICONERROR|MB_ICONSTOP);item=MCI_MAKE_HMS(0,0,0); void play()MCI_PLAY_PARMS mciplayparms;ItemLength=GetLength(MCI_STATUS_LENGTH); /得到播放长度 ItemTo=MCI_MAKE_HMS(MCI_HMS_HOUR(ItemLength), MCI_HMS_MINUTE(ItemLength), MCI_HMS_SECOND(ItemLength); /根据长度计算出时、分、秒mciplayparms.dwCallback=NULL; mciplayparms.dwFrom=item; /播放起点mciplayparms.dwTo=ItemTo; /播放终点 mciSendCommand(mciopenparms.wDeviceID,MCI_PLAY,MCI_FROM|MCI_NOTIFY,(DWORD)(LPVOID)&mciplayparms);void pause()DWORD dwsf=GetLength(MCI_STATUS_POSITION);item=MCI_MAKE_MSF(MCI_MSF_MINUTE(dwsf), MCI_MSF_SECOND(dwsf), MCI_MSF_FRAME(dwsf);mciSendCommand(mciopenparms.wDeviceID,MCI_PAUSE,0,0);void resume() mciSendCommand(mciopenparms.wDeviceID,MCI_RESUME,0,0);void stop()mciSendCommand(mciopenparms.wDeviceID,MCI_STOP,0,0);mciSendCommand(mciopenparms.wDeviceID,MCI_SEEK,MCI_SEEK_TO_START,0); mciSendCommand(mciopenparms.wDeviceID,MCI_CLOSE,0,0);item=MCI_MAKE_HMS(0,0,0);DWORD setvolume(DWORD vol)MCI_DGV_SETAUDIO_PARMS mcisetvolume;mcisetvolume.dwCallback=NULL;mcisetvolume.dwItem=MCI_DGV_SETAUDIO_VOLUME;mcisetvolume.dwValue=vol;mciSendCommand(mciopenparms.wDeviceID,MCI_SETAUDIO,MCI_DGV_SETAUDIO_VALUE|MCI_DGV_SETAUDIO_ITEM,(DWORD)(LPVOID)&mcisetvolume);return 0;void CMyDlg:Onabout() CAboutDlg dlg;dlg.DoModal();/ TODO: Add your control notification handler code herevoid CMyDlg:Onexit() CDialog:OnCancel();/ TODO: Add your control notification handler code herevoid CMyDlg:Onplay() DWORD cdlen=GetLength(MCI_STATUS_LENGTH);play();m_process.SetRange(0,cdlen);SetTimer(0,1000,NULL);/ TODO: Add your control notification handler code herevoid CMyDlg:Onfilechoice()char szfilefilter=mp3文件(*.mp3)|*.mp3| wma文件(*.wma)|*.wma|wav文件(*.wav)|*.wav|所有文件(*.*)|*.*|;CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY,szfilefilter);if(dlg.DoModal()=IDOK) CString strFilepath=dlg.GetPathName(); CString strFilename=dlg.GetFileName(); SetDlgItemText(IDC_filename,strFilename); open(strFilepath); GetDlgItem(IDC_play)-EnableWindow(true); GetDlgItem(IDC_pause)-EnableWin
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 日语试题试卷及答案
- 税法总论考试题及答案
- 2025年广东省合成氨工艺操作证理论考试练习题库(含答案)
- 2025年阜阳市颍泉区选调区内教师考试笔试试题(含答案)
- 2025年达州市大竹县城区学校考调教师笔试试题(含答案)
- 2025年注册会计师模拟题和答案分析
- 2024年劳务员之劳务员专业管理实务练习题一及答案
- 北京热力保密知识培训课件
- 足部损伤诊疗与护理考核试题及答案
- 2025年临床VTE防治考核题及答案
- 新航标职业英语语音技能教程unit
- 天津高考语文卷各题型思路要点提示
- ktv转让标准合同范本(3篇)
- 普外科医疗质量评价体系与考核标准
- 普通高中语文课程标准测试题及答案
- 正确认识胰岛素
- 吞咽障碍患者的营养支持课件
- DL∕T 617-2019 气体绝缘金属封闭开关设备技术条件
- 诺如病毒感染暴发调查和预防控制技术指南(2023版)
- 班级管理(第3版)教学课件汇总全套电子教案(完整版)
- 行政处罚案卷制作规范课件
评论
0/150
提交评论