简体   繁体   English

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

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

I wish to use mciSendString to play a basic wav file, from a point say 20 seconds from the beginning of the audio. 我希望使用mciSendString播放一个基本的wav文件,从音频开始起20秒。 I have tried using it to just open and play a basic wav file in the same directory as the program, however to no avail. 我尝试使用它来打开和播放与该程序相同目录中的基本wav文件,但是无济于事。 This is the basic code I have: 这是我的基本代码:

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

The output to the console is: 控制台的输出为:

0
0
0
0
320
0

So I understand there is an error in the play mciSendString which translates to "MCIERR_WAVE_OUTPUTSINUSE". 因此,我知道在播放mciSendString时发生错误,该错误转换为“ MCIERR_WAVE_OUTPUTSINUSE”。 What does this mean and how can i fix this? 这是什么意思,我该如何解决?

In addition, since you want to start playing WAV files from a specific location, such as 20 seconds, you need to modify it to this way. 此外,由于您要从特定位置(例如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