繁体   English   中英

如何从mciSendString()修复此错误并使其发出声音?

[英]How can you fix this error from mciSendString() and make it play a sound?

我希望使用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”。 这是什么意思,我该如何解决?

此外,由于您要从特定位置(例如20秒)开始播放WAV文件,因此需要对其进行修改。

#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");
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM