0

I am making a simple music playback program using the lame library and MCI. After decoding MP3 files into wav files, use MCIWndCreate and MCIWndPlay to play music. All functions are working fine, but there was a problem with setting the volume. I found and used a method called MCIWndSetVolume(hWnd, iVol) for setting the volume. But I get the error like below. If you know which part is the problem, please give me a little advice. Thank you so much for reading and answering my questions. Error Message -> The specified command is not recognized by the driver.

void CMP3PlayerDlg::Wav(CString strFileName)
{
    m_hWav = NULL;
    m_nowWav = strFileName;
    CString strWav;
    strWav.Format(WAV_FILE_PATH + strFileName);
    if(m_hWav == NULL)
    {
        m_hWav = MCIWndCreate(this->GetSafeHwnd(), AfxGetInstanceHandle(), WS_CHILD | WS_VISIBLE | MCIWNDF_NOMENU , strWav);
    }
    else
    {
        MCIWndHome(m_hWav);
    }
    MCIWndPlay(m_hWav);
    m_bPause = FALSE;
    m_btnPlay.EnableWindow(FALSE);
}

void CMP3PlayerDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
    // TODO: 여기에 메시지 처리기 코드를 추가 및/또는 기본값을 호출합니다.
    if(IDC_SLIDER_VOLUM == pScrollBar->GetDlgCtrlID())
    {
        int nPos = m_SliderVol.GetPos();
        CString strPos;
        strPos.Format("%d", nPos);
        m_EditVol.SetWindowText(strPos);
    }
    CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);
}





void CMP3PlayerDlg::OnEnChangeEditVolum()
{
    // TODO:  여기에 컨트롤 알림 처리기 코드를 추가합니다.
    CString strPos;
    m_EditVol.GetWindowText(strPos);
    int nPos = _ttoi(strPos);
    m_SliderVol.SetPos(nPos);
    MCIWndSetVolume(m_hWav, nPos);
}

This is a volume control method using playback and slider bar.

Jungwon
  • 1,038
  • 7
  • 20
  • Unrelated: The `else { MCIWndHome(m_hWav); }` will never be executed since you start with `m_hWav = NULL;` – Ted Lyngmo Mar 22 '21 at 08:18
  • m_hWav is a handle value, and MCIWndCreate is performed, and playback stop and pause are all performed with the value obtained through m_hWav. But why is it NULL? Could you give me a little hint? – Jungwon Mar 22 '21 at 08:28
  • In your top function, you start by setting `m_hWav = NULL;` so the `else` part with `MCIWndHome(m_hWav);` can never be executed - but as I said, this is probably unrelated to the `MCIWndSetVolume` error. – Ted Lyngmo Mar 22 '21 at 08:29
  • I have to think more and try. Thank you so much for your interest and answers to my questions. – Jungwon Mar 22 '21 at 08:34
  • *"I get the error"* - What error do you get? – IInspectable Mar 22 '21 at 08:57
  • Set the nPos value using the weight bar. If you apply the volume with nPos value with the MCIWnd SetVolume method, The specified command is not recognized by the driver. – Jungwon Mar 22 '21 at 09:09

1 Answers1

0
void CMP3PlayerDlg::OnEnChangeEditVolum()
{
    // TODO:  여기에 컨트롤 알림 처리기 코드를 추가합니다.
    CString strPos;
    CString strFile;
    m_EditVol.GetWindowText(strPos);
    int nPos = _ttoi(strPos);
    if(nPos > 100)
    {
        strPos = "100";
        nPos = 100;
        m_EditVol.SetWindowText("100");
    }
    m_SliderVol.SetPos(nPos);
    waveOutSetVolume((HWAVEOUT)m_hWav, (DWORD)(nPos));

}

You can now control the volume using the waveOutSetVolume method. Thank you for reading and answering my questions.

Jungwon
  • 1,038
  • 7
  • 20