mciSendString randomly stops working

479 Views Asked by At

My code

    char MusicLoc [50][200];
    char Music [50][50];
    int MusicBox(int IndexMusic)
    {
    std::string rawloc = ((std::string)"open \""+MusicLoc[IndexMusic]+Music[IndexMusic]+"\"type mpegvideo alias "+Music[IndexMusic]);`
    mciSendString(rawloc.c_str(), NULL, 0, 0); 
    mciSendString(((std::string)"play "+Music[IndexMusic]).c_str(), NULL, 0, 0);
    return 0;
    }

MusicLoc contains the path and Music contains the filename, so MusicLoc[1]+Music[1] would be C:\etc\etc\etc\audio.mp3 , it worked fine at first but then it randomly stopped working , I have tried everything and it doesn't work so I am gonna guess using mciSendString isn't recomended, so does anyone knows about a good and lightweight audio library?

Edit: The first mciSendString returns 266, and the second one return 275, if its of any use, but I really haven't found good documentation about them.

Also GetLastError says there is no error...

1

There are 1 best solutions below

0
On

If there is no error, the return from mciSendString should be zero. Your question suggests that you are getting errors!

To decode the errors nicely, use mciGetErrorString

Something like this ( ripped from my code, so you will have to adjust variable names, etc )

    wchar_t cmd[250];
    swprintf(cmd,249,L"open %s alias an1",fname1.c_str());
    err = mciSendString(cmd, 0, 0, 0 );
    if( err ) throw err;

...

catch ( unsigned int& err ) {
    wprintf(L"Playing %s %s %s\n",fname1.c_str(),fname2.c_str(),fname3.c_str());
    wchar_t msg[128];
    mciGetErrorString( err, msg,128 );
    wprintf(L"%s\n",msg);