Search code examples
c++winapiaudiomci

mciSendString() setaudio volume error 261


I'm using MCI to do some sound-related stuff, and everything works, except I cannot alter the volume. I have the following code:

mciSendStringA("open res/theme.wav type waveaudio alias maintheme", nullptr, 0, nullptr);
MCIERROR error = mciSendStringA("setaudio maintheme volume to 50", nullptr, 0, nullptr);

error is 261. The program works fine but the volume does not change. Any suggestions on what's wrong? (Two pages of google searching and there's nothing)


Solution

  • According to the documentation:

    setaudio command

    The setaudio command sets values associated with audio playback and capture. Digital-video and VCR devices recognize this command.

    ...

    lpszAudio
    Flag for audio playback and capture. The following table lists device types that recognize the setaudio command and the flags used by each type.

    digitalvideo
    vcr

    Your audio playback is using a waveaudio device, which does not support the setaudio command.

    In order to set the volume of audio playback, you will have to switch to the WaveOut API for playback, then you can use waveOutSetVolume().