使用MCI播放媒体文件

来源:互联网 发布:大学智慧树网络课程 编辑:程序博客网 时间:2024/04/29 20:42

#include<stdio.h>
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib")

bool MCI_Play(LPCTSTR file)
{
//use mciSendCommand
  MCI_OPEN_PARMS mciOpen = {0};
  mciOpen.lpstrElementName = file;
  MCIERROR mciError = mciSendCommand(0,MCI_OPEN, MCI_OPEN_ELEMENT ,(DWORD)&mciOpen);
  if(mciError)
  {
    char buf[128];
    mciGetErrorString(mciError,buf,128);
    CString mess_str;
    mess_str.Format("send MCI_OPEN command failed:%s/n",buf);
    AfxMessageBox(mess_str);
    return(false);
  }
 
  MCI_PLAY_PARMS mciPlay;
  mciError = mciSendCommand(mciOpen.wDeviceID,MCI_PLAY,0 ,(DWORD)&mciPlay);
  if(mciError)
  {
    mciSendCommand(mciOpen.wDeviceID, MCI_CLOSE, 0, NULL);
    AfxMessageBox("send MCI_PLAY command failed/n");
    return(false);
  }

  return(true);
}