WinAPI学习 - mciSendString音频播放

关于这个mciSendString函数,MSDN给出的说明如下:

The mciSendString function sends a command string to an MCI device. The device that the command is sent to is specified in the command string.

大概是说mciSendString是用来和MCI(Media Control Interface)设备沟通的函数,通过一些字符串命令。其API如下:

MCIERROR mciSendString(
  LPCTSTR lpszCommand,
  LPTSTR lpszReturnString,
  UINT cchReturn,
  HANDLE hwndCallback
);

Parameters

lpszCommand

Pointer to a null-terminated string that specifies an MCI command string. For a list, see Multimedia Command Strings.

lpszReturnString

Pointer to a buffer that receives return information. If no return information is needed, this parameter can be NULL.

cchReturn

Size, in characters, of the return buffer specified by the lpszReturnString parameter.

hwndCallback

Handle to a callback window if the "notify" flag was specified in the command string.

一、简单音频播放实现

#include 
#pragma comment(lib,"winmm.lib")

char mciCmd[] = "open HappyBirthday.mp3 alias betabin";

mciSendString(mciCmd, NULL, 0, NULL);
mciSendString("play betabin repeat", NULL, 0, NULL);

以上代码可以用于简单的音频播放。(单曲循环HappyBirthday.mp3这首歌。)

二、字符串命令

这里说的字符串命令就是指mciSendString的第一个参数了,给个MSDN的链接(http://msdn.microsoft.com/en-us/library/windows/desktop/dd743572(v=vs.85).aspx)。

其实和DOS之类的命令差不多,一个指令(open, status, set, play...)后面有不同的参数。MSDN都给出了链接。蛮简洁的。

你可能感兴趣的:(Windows)