基于出色的答案How to play or open *.mp3 or *.wav sound file in c++ program? 通过用户@FarewellStackExchange(我希望他还在我们身边),我实现了mp3
使用 Windows 媒体控制界面 (MCI) 播放音频的功能(请参阅https://docs.microsoft.com/en-us/windows/desktop/Multimedia /mci )。
但我也希望它播放视频文件中的音频而不显示视频。我有一个问题,因为视频窗口总是短暂显示(闪光)。所以我的问题是:现在有没有人在发出命令之前如何禁用/隐藏窗口?play
或者有人知道另一种方式,例如不使用 MCI?
以下是一个最小示例:
#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);
}