• Advertisement
Sign in to follow this  

length of file in mci

This topic is 4214 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello all i got a question about mci: after opening a file, how can i know the file length without playing it? like 50 seconds and etc?? thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
thanks
and another question:
how do i know where the file is now??
i started playing it.... and after a few minuts i want to see where is it
how do i do that???
should i set a timer or somthing?? or there is a command?

thanks in advance

Share this post


Link to post
Share on other sites
Exactly the same way as above, but with "position" instead of "length"...

Share this post


Link to post
Share on other sites
ok thanks.
how do i get the information??
int a = mcisendstring(...) ??

what is the data which coming back?? integer???

thanks in advance

Share this post


Link to post
Share on other sites
No, read the documentation.

Quote:

MCIERROR mciSendString(
LPCTSTR lpszCommand,
LPTSTR lpszReturnString,
UINT cchReturn,
HANDLE hwndCallback
);

lpszReturnString

Pointer to a buffer that receives return information. If no return information is needed, this parameter can be NULL.

cchReturn

Size, in characters, of the return buffer specified by the lpszReturnString parameter.

Share this post


Link to post
Share on other sites
MCI is really quite old. I suggest either rolling your own player on top of WAV or OGG and DirectSound, or using DirectShow to play the file. Once XACT starts supporting better compressed audio banks, that'll probably be the best tool to use for game audio on Windows.

Share this post


Link to post
Share on other sites
well.. i tried to do somthing... that it gets it and give it to me in a msg box so i'll see it.
but instead of doing that.. it just gives me an empty msg box...
here is the code: (i'm working in C++ btw)


char ms[6];
char loc[260];
strcpy(loc, "status \"");
strcat(loc,p);
strcat(loc,"\" length");
mciSendString(loc,ms,6,0);
MessageBox(NULL,ms,"ERROR",MB_OK|MB_ICONEXCLAMATION);



anyone has any idea whats wrong here and how to fix this?? thanks in advance

Share this post


Link to post
Share on other sites
I'm guessing your buffer ain't large enough, and since you're working with C++ you should be using std::string...

Share this post


Link to post
Share on other sites
Quote:
Original post by raz0r
I'm guessing your buffer ain't large enough, and since you're working with C++ you should be using std::string...


i dont understand what u mean..
and i used a 255 buffer before that one

Share this post


Link to post
Share on other sites
Just wrote this, works fine for me...

std::pair <std::string, DWORD> Dummy(std::string const & rFilePath, std::streamsize iStreamWidth = 0x02)
{
std::pair <std::string, DWORD> pResult;

if(rFilePath.empty())
return pResult;

std::vector <char> pInputBuffer(32, char());

DWORD dwDummy = ::mciSendString(std::string("status " + rFilePath + " length").c_str(), & pInputBuffer.front(),
static_cast <UINT> (pInputBuffer.size()), NULL);

::mciSendString(std::string("close " + rFilePath).c_str(), NULL, NULL, NULL);

if(dwDummy)
{
pResult.second = dwDummy;

return pResult;
}

std::stringstream pDummyStream(std::string(pInputBuffer.begin(), pInputBuffer.end()));

pDummyStream >> pResult.second;

pDummyStream.str(std::string());

pDummyStream << std::setw(iStreamWidth) << std::setfill('\x30') << pResult.second / 1000 / 60 % 60 <<
'\x3A' << std::setw(iStreamWidth) << std::setfill('\x30') << pResult.second / 1000 % 60;

pResult.first = pDummyStream.str();

return pResult;
}





*.first -> mm:ss
*.second -> total time expressed in MS

If mciSendString fails, *.second will contain the result of the call, and *.first will be empty.

P.S.
Also, mciGetErrorString is quite handy...

[Edited by - raz0r on July 6, 2006 4:05:04 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by raz0r
Just wrote this, works fine for me...
*** Source Snippet Removed ***
*.first -> mm:ss
*.second -> total time expressed in MS

If mciSendString fails, *.second will contain the result of the call, and *.first will be empty.

P.S.
Also, mciGetErrorString is quite handy...


never used this kind of stuff..
can you show me where i need to put it and how i use it?

thanks in advance

Share this post


Link to post
Share on other sites
Yes, for example:
std::pair <std::string, DWORD> pDummy(Dummy("C:\\Dummy.mp3"));

std::cout << pDummy.first << " - " << pDummy.second; //Output should look something like "00:00 - 0" if no error occured, otherwise, *.first is empty and *.second is the MCI error code...

Share this post


Link to post
Share on other sites
can u show me an example without std stuff ???
just one working example

thanks in advance

Share this post


Link to post
Share on other sites
Quote:
Original post by mc30900
can u show me an example without std stuff ???
just one working example

thanks in advance

Why are you trying to avoid using the STL?
In any case, from your original example:

char * pszFilePath = "C:\\Target File.mp3";
char szCommandBuffer[512] = {char()}, szReturnBuffer[32] = {char()};

::sprintf(szCommandBuffer, "open \"%s\"", pszFilePath);

DWORD dwDummy = ::mciSendString(szCommandBuffer, NULL, NULL, NULL);

if(!dwDummy)
{
::sprintf(szCommandBuffer, "status \"%s\" length", pszFilePath);

dwDummy = ::mciSendString(szCommandBuffer, szReturnBuffer, sizeof(szReturnBuffer), NULL);

::sprintf(szCommandBuffer, "close \"%s\"", pszFilePath);

::mciSendString(szCommandBuffer, NULL, NULL, NULL);
}

if(dwDummy)
;//Handle error either from the first call, or the second call.

::MessageBox(NULL, szReturnBuffer, NULL, MB_OK + MB_ICONEXCLAMATION);




Keep in mind that this is VERY unsafe...

Share this post


Link to post
Share on other sites
ok lets assume i get
375320

how much is that in seconds and in minuts?? and how do i know?? thanks in advance

Share this post


Link to post
Share on other sites
Quote:
Original post by mc30900
ok lets assume i get
375320

how much is that in seconds and in minuts?? and how do i know?? thanks in advance

Scroll up...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement