0

我希望使用 mciSendString 播放一个基本的 wav 文件,从音频开始的 20 秒开始。我曾尝试使用它在与程序相同的目录中打开并播放基本的 wav 文件,但无济于事。这是我的基本代码:

int main() {
    char lpszReturnString[16384];
    MCI_PLAY_PARMS song = { NULL, 0, 15 };
    MCIERROR open = mciSendString("open \"C:\\Users\\ethan\\source\\repos\\Project2\\Project2\\America.wav\" type waveaudio alias America", lpszReturnString, lstrlen(lpszReturnString), NULL);
    MCIERROR set = mciSendString("set America time format samples", lpszReturnString, lstrlen(lpszReturnString), NULL);
    MCIERROR play = mciSendString("play America from 1", lpszReturnString, lstrlen(lpszReturnString), NULL);
    cout << LOWORD(open) << endl;
    cout << HIWORD(open) << endl;
    cout << LOWORD(set) << endl;
    cout << HIWORD(set) << endl;
    cout << LOWORD(play) << endl;
    cout << HIWORD(play) << endl;
    system("pause");
}

控制台的输出是:

0
0
0
0
320
0

所以我知道播放 mciSendString 中有一个错误,它转换为“MCIERR_WAVE_OUTPUTSINUSE”。这是什么意思,我该如何解决?

4

1 回答 1

0

另外,由于要从特定位置开始播放WAV文件,比如20秒,所以需要修改成这种方式。

#include <Windows.h>
#include <iostream>
#pragma comment (lib,"Winmm.lib")
using namespace std;

int main() {
        char lpszReturnString[16384];
        memset(lpszReturnString, 0, sizeof(lpszReturnString));
        MCI_PLAY_PARMS song = { NULL, 0, 15 };
        MCIERROR open = mciSendString("open \"C:\\Users\\ethan\\source\\repos\\Project2\\Project2\\America.wav\" type waveaudio alias America" , lpszReturnString, sizeof(lpszReturnString), NULL);
        MCIERROR set = mciSendString("set America time format ms ", lpszReturnString, sizeof(lpszReturnString), NULL);
        MCIERROR seek = mciSendString("seek America to 20000", NULL, 0, 0);
        MCIERROR play = mciSendString("play America", lpszReturnString, sizeof(lpszReturnString), NULL);
        cout << LOWORD(open) << endl;
        cout << HIWORD(open) << endl;
        cout << LOWORD(set) << endl;
        cout << HIWORD(set) << endl;
        cout << LOWORD(play) << endl;
        cout << HIWORD(play) << endl;;
        system("pause");
}
于 2019-07-01T10:14:57.520 回答