小弟实在是太菜,这代码也简单的不能再简单了:
void CMediaplayerDlg::OnButton2() 
{
MCI_OPEN_PARMS open={0};
char str1[100];
POSITION pos=m_list1.GetFirstSelectedItemPosition();
if(pos==NULL)
{
MessageBox("没有选择歌曲","提示",MB_OK);
}
else
{
int nItem=m_list1.GetNextSelectedItem(pos);
CString str=m_list1.GetItemText(nItem,2);
open.lpstrElementName=str;
open.lpstrDeviceType="mpegvideo";
DWORD err;
err=mciSendCommand(0,MCI_OPEN,MCI_OPEN_TYPE|MCI_OPEN_ELEMENT|MCI_WAIT,(DWORD)(LPVOID)&open);
if(err==0)
{
MCI_PLAY_PARMS play;
play.dwFrom=0;
play.dwCallback=NULL;
mciSendCommand(open.wDeviceID,MCI_PLAY,0,(DWORD)&play);
}
else
{
mciGetErrorString(err,(LPSTR)str1,100);
MessageBox(str1);
}
}}

解决方案 »

  1.   

    open.lpstrDeviceType="mpegvideo";//??
    //好的是:
    mciOpenParms.lpstrDeviceType=(LPSTR)MCI_DEVTYPE_WAVEFORM_AUDIO;
      

  2.   

    windows那个播放的api实在是太不稳定了,google一下吧,有好多人都遇到过
      

  3.   

    是不是文件路径问题,好像mci这个函数只认识短路径和文件名
    你可以将文件路径名称转为短格式再播放,或者先放到c盘根目录去测试一下,当然文件名也改为8.3格式的
      

  4.   

    参考CWave:DWORD CWave::Play(CWnd* pWnd,LPCSTR pFileName)
    {
        MCI_OPEN_PARMS mciOpenParms;
        //initialize structure
        memset(&mciOpenParms,0,sizeof(MCI_OPEN_PARMS));//  mciOpenParms.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_SEQUENCER;//MIDI类型
    //  mciOpenParms.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_WAVEFORM_AUDIO;
        //set the file name to be played
        mciOpenParms.lpstrElementName=pFileName;    //first open the device
        DWORD dwResult=mciSendCommand(m_nDeviceID,MCI_OPEN,   MCI_OPEN_ELEMENT,(DWORD)(LPVOID)&mciOpenParms);    //display error message if failed
        if(dwResult)
        {
            DisplayErrorMsg(dwResult);
        }
        else //if successful,instruct the device to play the WAV file
        {
            //save element indentifier
            m_nElementID=mciOpenParms.wDeviceID;        MCI_PLAY_PARMS mciPlayParms;        //set the window that will receive notification message
            mciPlayParms.dwCallback=(DWORD)pWnd->m_hWnd;        //instruct device to play file
            dwResult=mciSendCommand(m_nElementID,MCI_PLAY,MCI_NOTIFY,(DWORD)(LPVOID)&mciPlayParms);        //display error and close element if failed
            if(dwResult)
            {
                DisplayErrorMsg(dwResult);
                Stop();
            }
        }
        //return result of MCI operation
        return dwResult;
    }