Does mciSendString must have “wait” in order to hear sound?

强颜欢笑 提交于 2019-12-12 13:15:55

问题


I'm trying to write a mp3 player using mci functions.(win 7 64bit,vs2010,c++)

when i try to play a mp3 file with the flag "wait" i can hear the file but everything else is stuck until the file ends playing, if i remove the flag "wait" i can continue working but can't hear a thing.

here is a sample of the code:

unsigned long __stdcall PlayThread(void *myParam)
{

    char* nameOfMp3 = (char*)myParam;
    char* cmd = new char[MAX_PATH];
    sprintf(cmd,"open \"%s\" type MPEGvideo alias myFile",nameOfMp3);

    mciSendString(cmd,NULL,0,0);
    mciSendString("play myFile wait",NULL,0,0);//here is the "wait" flag
    mciSendString("close myFile",NULL,0,0);

    return 0;
}

i removed the checking of the return value of the mci commends but i already cheacked them and they were fine in both cases.

am i doing something wrong?


回答1:


If you remove your wait flag, you can't have the next line closing your file ( close myFile ) as you're not giving time for the play to happen.

Having this flag on, allows you indeed to wait until the called function completed. The reason you can actually play your file. In the case you removed it, it will initiate the play and immediately after close it.

To close your file after use, you need to somehow wait or test your media has finished playing. You can achieve this by regularly testing the status by doing the following mciSendString("status myFile mode"). Possible values are "not ready", "paused", "playing", and "stopped" as described in the status documentation.

I think you have enough information from there to finish it ;)

Happy coding.



来源:https://stackoverflow.com/questions/16962645/does-mcisendstring-must-have-wait-in-order-to-hear-sound

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!