MCI音乐播放器
来源:互联网 发布:python readline 编辑:程序博客网 时间:2024/05/16 14:20
MCI做的简单的音乐播放器,有播放、暂停、停止、快放/慢放、快进/回退等主要功能,并且可以播放视频,不过视频播放有BUG,还请见谅。播放音频有很无奈的BUG,播放时进度条前进会影响声音卡顿,求解……
// MCIPlayerDlg.h : 头文件#pragma once#include "afxcmn.h"// CMCIPlayerDlg 对话框class CMCIPlayerDlg : public CDialogEx{// 构造public:CMCIPlayerDlg(CWnd* pParent = NULL);// 标准构造函数// 对话框数据enum { IDD = IDD_MCIPLAYER_DIALOG };protected:virtual void DoDataExchange(CDataExchange* pDX);// DDX/DDV 支持// 实现protected:HICON m_hIcon;// 生成的消息映射函数virtual BOOL OnInitDialog();afx_msg void OnSysCommand(UINT nID, LPARAM lParam);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();DECLARE_MESSAGE_MAP()private:unsigned int speed;unsigned int volume;CString song;CSliderCtrl slider;bool start;void changeSpeed(unsigned int);static DWORD WINAPI ThreadProc(LPVOID lpParam);void updatePro();public:afx_msg void OnBnClickedBtnPlay();afx_msg void OnBnClickedBtnPause();afx_msg void OnBnClickedBtnStop();afx_msg void OnBnClickedBtnFast();afx_msg void OnBnClickedBtnSlow();afx_msg void OnBnClickedBtnChild();afx_msg void OnBnClickedBtnDeepman();afx_msg void OnBnClickedBtnHighwoman();afx_msg void OnBnClickedBtnAchead();afx_msg void OnBnClickedBtnBack();afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);afx_msg void OnNMCustomdrawSlider2(NMHDR *pNMHDR, LRESULT *pResult);afx_msg void OnTimer(UINT_PTR nIDEvent);int position;CSliderCtrl slider_progress;afx_msg void OnBnClickedBtnOpen();};
// MCIPlayerDlg.cpp : 实现文件#include "stdafx.h"#include "MCIPlayer.h"#include "MCIPlayerDlg.h"#include "afxdialogex.h"#include <mmsystem.h> #pragma comment(lib,"winmm.lib")#ifdef _DEBUG#define new DEBUG_NEW#endif// CMCIPlayerDlg 对话框CMCIPlayerDlg::CMCIPlayerDlg(CWnd* pParent /*=NULL*/): CDialogEx(CMCIPlayerDlg::IDD, pParent), speed(1000), position(0), volume(600), start(FALSE){m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}void CMCIPlayerDlg::DoDataExchange(CDataExchange* pDX){CDialogEx::DoDataExchange(pDX);DDX_Control(pDX, IDC_SLIDER1, slider);DDX_Control(pDX, IDC_SLIDER2, slider_progress);}BEGIN_MESSAGE_MAP(CMCIPlayerDlg, CDialogEx)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BTN_PLAY, &CMCIPlayerDlg::OnBnClickedBtnPlay)ON_BN_CLICKED(IDC_BTN_PAUSE, &CMCIPlayerDlg::OnBnClickedBtnPause)ON_BN_CLICKED(IDC_BTN_STOP, &CMCIPlayerDlg::OnBnClickedBtnStop)ON_BN_CLICKED(IDC_BTN_FAST, &CMCIPlayerDlg::OnBnClickedBtnFast)ON_BN_CLICKED(IDC_BTN_SLOW, &CMCIPlayerDlg::OnBnClickedBtnSlow)ON_BN_CLICKED(IDC_BTN_CHILD, &CMCIPlayerDlg::OnBnClickedBtnChild)ON_BN_CLICKED(IDC_BTN_DEEPMAN, &CMCIPlayerDlg::OnBnClickedBtnDeepman)ON_BN_CLICKED(IDC_BTN_HIGHWOMAN, &CMCIPlayerDlg::OnBnClickedBtnHighwoman)ON_BN_CLICKED(IDC_BTN_ACHEAD, &CMCIPlayerDlg::OnBnClickedBtnAchead)ON_BN_CLICKED(IDC_BTN_BACK, &CMCIPlayerDlg::OnBnClickedBtnBack)ON_WM_HSCROLL()ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER2, &CMCIPlayerDlg::OnNMCustomdrawSlider2)ON_WM_TIMER()ON_BN_CLICKED(IDC_BTN_OPEN, &CMCIPlayerDlg::OnBnClickedBtnOpen)END_MESSAGE_MAP()// CMCIPlayerDlg 消息处理程序void CMCIPlayerDlg::changeSpeed(unsigned int p_speed){LPTSTR str_temp = new TCHAR[100];wsprintf(str_temp, "set temp_song speed %d", p_speed);mciSendString(str_temp, NULL, 0, NULL);return;}void CMCIPlayerDlg::OnBnClickedBtnPlay(){// TODO: Add your control notification handler code hereCString f_open, f_movie;HWND hWn = GetDlgItem(IDC_P)->GetSafeHwnd();f_open.Format("open %s type MPEGVideo alias temp_song parent %u Style %u notify", song, hWn, WS_CHILD);mciSendString(f_open.GetBuffer(f_open.GetLength()), NULL, 0, NULL);f_movie.Format("put temp_song window at 0 0 %d %d", 330, 184);mciSendString(f_movie, NULL, 0, NULL);mciSendString("play temp_song", NULL, 0, NULL);if (start){return;}slider.SetRange(1, 1000);slider.SetTicFreq(10);slider.SetPos(600);mciSendString("setaudio temp_song volume to 600", NULL, 0, NULL);char le[1024];mciSendString("status temp_song length", le, sizeof(le), 0);int temp_le = atoi(le);slider_progress.SetRange(1, temp_le);slider_progress.SetPos(0);SetTimer(1, 1000, NULL);//hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, (LPVOID)this, 0, NULL);start = TRUE;}void CMCIPlayerDlg::OnBnClickedBtnPause(){// TODO: Add your control notification handler code heremciSendString("pause temp_song", NULL, 0, NULL);}void CMCIPlayerDlg::OnBnClickedBtnStop(){// TODO: Add your control notification handler code heremciSendString("stop temp_song", NULL, 0, NULL);mciSendString("close temp_song", NULL, 0, NULL);speed = 1000;start = FALSE;KillTimer(1);//CloseHandle(hThread);}void CMCIPlayerDlg::OnBnClickedBtnFast(){// TODO: Add your control notification handler code herespeed += 100;changeSpeed(speed);}void CMCIPlayerDlg::OnBnClickedBtnSlow(){// TODO: Add your control notification handler code herespeed -= 100;changeSpeed(speed);}void CMCIPlayerDlg::OnBnClickedBtnChild(){// TODO: Add your control notification handler code herespeed = 1400;changeSpeed(speed);}void CMCIPlayerDlg::OnBnClickedBtnDeepman(){// TODO: Add your control notification handler code herespeed = 800;changeSpeed(speed);}void CMCIPlayerDlg::OnBnClickedBtnHighwoman(){// TODO: Add your control notification handler code herespeed = 1200;changeSpeed(speed);}void CMCIPlayerDlg::OnBnClickedBtnAchead(){// TODO: Add your control notification handler code hereCString temp;char po[256];mciSendString("status temp_song position", po, 255, 0);position = StrToInt(po) + 4000;temp.Format("seek temp_song to %d", position);mciSendString(temp.GetBuffer(temp.GetLength()), NULL, 0, NULL);mciSendString("play temp_song", NULL, 0, NULL);}void CMCIPlayerDlg::OnBnClickedBtnBack(){// TODO: Add your control notification handler code hereCString temp;char po[256];mciSendString("status temp_song position", po, 255, 0);if ((position = StrToInt(po) - 4000) < 0){position = 0;}temp.Format("seek temp_song to %d", position);mciSendString(temp.GetBuffer(temp.GetLength()), NULL, 0, NULL);mciSendString("play temp_song", NULL, 0, NULL);}void CMCIPlayerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar){// TODO: Add your message handler code here and/or call defaultvolume = slider.GetPos();CString temp;temp.Format("setaudio temp_song volume to %d", volume);mciSendString(temp.GetBuffer(temp.GetLength()), NULL, 0, NULL);CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);}void CMCIPlayerDlg::OnNMCustomdrawSlider2(NMHDR *pNMHDR, LRESULT *pResult){LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);// TODO: Add your control notification handler code hereCString temp;position = slider_progress.GetPos();temp.Format("seek temp_song to %d", position);mciSendString(temp.GetBuffer(temp.GetLength()), NULL, 0, NULL);mciSendString("play temp_song", NULL, 0, NULL);*pResult = 0;}void CMCIPlayerDlg::OnTimer(UINT_PTR nIDEvent){// TODO: Add your message handler code here and/or call defaultchar po[256];mciSendString("status temp_song position", po, 255, 0);int position = StrToInt(po);slider_progress.SetPos(position);CDialogEx::OnTimer(nIDEvent);}DWORD WINAPI CMCIPlayerDlg::ThreadProc(LPVOID lpParam){//SetTimer((HWND)lpParam, 1, 1000, NULL);//CMCIPlayerDlg* p = (CMCIPlayerDlg*)lpParam;while (TRUE){Sleep(1000);((CMCIPlayerDlg*)lpParam)->updatePro();}return 0;}void CMCIPlayerDlg::updatePro(){//char po[256];//mciSendString("status temp_song position", po, 255, 0);//int position = StrToInt(po);//slider_progress.SetPos(position);return;}void CMCIPlayerDlg::OnBnClickedBtnOpen(){// TODO: Add your control notification handler code hereCFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"音频文件(*.mp3;*.wav)|*.mp3;*.wav|""视频文件(*.f4v;*.mp4;*.avi)|*.f4v;*.mp4;*.avi|");if(dlg.DoModal()==IDOK){song = dlg.GetPathName();OnBnClickedBtnPlay();}}
- MCI音乐播放器
- 基于MCI的音乐播放器
- 使用MCI接口播放音乐
- 使用MCI接口播放音乐
- MFC入门-MCI简单音乐播放器实现
- 使用MCI播放音乐文件,MFC音乐播放
- 使用MCI播放音乐文件,MFC音乐播放
- MFC下MCI的使用播放音乐
- MCI实现播放器
- [更新]基于MFC对话框并使用MCI接口的音乐播放器
- 播放器MCI小程序
- 用MCI命令做一个播放器
- MCI播放器在VB中实现
- 用MCI命令做一个播放器
- MCI播放器在VB中实现
- Delphi TMediaPlayer播放音乐出现"no MCI device open"的错误的解决方法;循环播放
- 最简单的方法实现MIDI音乐循环播放 (不用在MCI回调中处理)
- 使用MCI播放媒体文件
- BT5学习笔记
- Java Spring Tutorial -- Custom Events
- Wince 5.0 6.0 7 开发环境
- 关于前端的一些小领会-下
- Copy
- MCI音乐播放器
- 牛刀小试、用SharePoint 实现请假管理功能
- Java Spring Tutorial -- autowire byName, byType, constructor
- Visual Studio:error MSB8020
- android下载指定的文件
- 含有三角函数的不等式
- CodeBlocks MinGW Windres 资源文件支持中文
- 男朋友就是你早晨醒来时第一个想到的那个人
- c实现"对象"