2

Based on the excellent answer How to play or open *.mp3 or *.wav sound file in c++ program? by user @FarewellStackExchange (I hope he is still with us), I implemented functionality to play mp3 audio using the Windows Media Control Interface (MCI) (see https://learn.microsoft.com/en-us/windows/desktop/Multimedia/mci).

But I also want it to play the audio from a video file without showing the video. I have a problem there because the video window is always briefly shown (a flash). So my question is: does anyone now how to disable/hide the window before the play command is issued? Or does someone know another way e.g. not using MCI?

The following is a minimal example:

#include <windows.h>
#pragma comment(lib, "Winmm.lib")

void mciExample(void)
{
    mciSendString("open \"myVideo.wmv\" type mpegvideo alias mymp3", 0,0,0);
    //
    // now the device "mymp3" is created. The following command will play the video:
    //
    mciSendString("play mymp3 from 0", 0,0,0);
    //
    // The following command hides the window, but it is first briefly shown.
    // How to avoid that? Placing the command before the "play" command has no effect.
    //
    mciSendString("window mymp3 state hide", 0,0,0);
}
Paul Ogilvie
  • 25,048
  • 4
  • 23
  • 41

0 Answers0