下面这段代码通过调用midi.Play(hWnd,mymusic.mid")可以实现播放.mid音乐,
可是调用midi.Play(hWnd,"mymusic.wav")就不能播放mymusic.wav波形文件。请问如何修改代码?(注:mymusic.wav和mymusic.mid文件都已拷贝到当前文件目录。)
DWORD CMidi::Play(HWND hwnd,char* MidiFile)
  {
    // 开启MIDI的硬件设备,我们使用一般内定值
    mciOpenParms.lpstrDeviceType = "sequencer";    // 这个参数就是要播放的MIDI文件名
    mciOpenParms.lpstrElementName = MidiFile;    // 使用Message的方式来播放MIDI而不是STRING的方式
    if (dwReturn = mciSendCommand(NULL, MCI_OPEN,
                   MCI_OPEN_TYPE | MCI_OPEN_ELEMENT,
                   (DWORD)(LPVOID) &mciOpenParms)
      return (dwReturn);    // The device opened successfully; get the device ID.
    wDeviceID = mciOpenParms.wDeviceID;    // Check if the output port is the MIDI mapper.
    mciStatusParms.dwItem = MCI_SEQ_STATUS_PORT;
    if (dwReturn = mciSendCommand(wDeviceID, MCI_STATUS, 
                   MCI_STATUS_ITEM, (DWORD)(LPVOID) &mciStatusParms))
    {
      mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
      return (dwReturn);
    }    // 为了达成重复播放的目的,必须让我们的程序能够接收到
    // MM_MCINOTIFY的讯息,这个函数调用的方式,就是传递
    // WM_PLAY讯息给装置,叫它开始播放。
    mciPlayParms.dwCallback = (DWORD) hwnd;
    if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY, 
                   (DWORD)(LPVOID) &mciPlayParms))
    {
      mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
      return (dwReturn);
    }
  return (0L);
  };

解决方案 »

  1.   

    mciOpenParms.lpstrDeviceType = "audiowave";
      

  2.   

    DWORD playWAVEFile(HWND hWndNotify, LPSTR lpszWAVEFileName)
    {
        UINT wDeviceID;
        DWORD dwReturn;
        MCI_OPEN_PARMS mciOpenParms;
        MCI_PLAY_PARMS mciPlayParms;    // Open the device by specifying the device and filename.
        // MCI will choose a device capable of playing the specified file.    mciOpenParms.lpstrDeviceType = "waveaudio";
        mciOpenParms.lpstrElementName = lpszWAVEFileName;
        if (dwReturn = mciSendCommand(0, MCI_OPEN,
           MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, 
           (DWORD)(LPVOID) &mciOpenParms))
        {
            // Failed to open device. Don't close it; just return error.
            return (dwReturn);
        }    // The device opened successfully; get the device ID.
        wDeviceID = mciOpenParms.wDeviceID;    // Begin playback. The window procedure function for the parent 
        // window will be notified with an MM_MCINOTIFY message when 
        // playback is complete. At this time, the window procedure closes 
        // the device.    mciPlayParms.dwCallback = (DWORD) hWndNotify;
        if (dwReturn = mciSendCommand(wDeviceID, MCI_PLAY, MCI_NOTIFY, 
            (DWORD)(LPVOID) &mciPlayParms))
        {
            mciSendCommand(wDeviceID, MCI_CLOSE, 0, NULL);
            return (dwReturn);
        }    return (0L);
    }
    //以上内容节选自MSDN,如果转载请标明出处!