• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1202
  • Last Modified:

Use mciSendString to play wav file

In my C++ program, I need to play a part of a big wav format  sound file.  For example, the file can be normally played for 10 min, I just want to play the sound for 10 seconds -- the part from the 15th second to 25th second.  I would like someone show me how to use mciSendString() for this.  THE CODE MUST WORK ON windows9x.
0
yingchunli
Asked:
yingchunli
  • 7
  • 4
1 Solution
 
jkrCommented:
See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mci_5vsj.asp ("Command Strings") - baiscally, you would use a function like

DWORD PlayFromTo(LPSTR lpstrAlias, DWORD dwFrom, DWORD dwTo)
{
    char achCommandBuff[128];

    // Form the command string.
    wsprintf(achCommandBuff, "play %s from %u to %u",
        lpstrAlias, dwFrom, dwTo);

    // Send the command string.
    return mciSendString(achCommandBuff, NULL, 0, NULL);
}
0
 
yingchunliAuthor Commented:
Hi jkr,

What should be the exact values for lpstrAlias, dwFrom, and dwTo with your PlayFromTo() function to play "test.wav" from the 15th second to the 25th second?
           
0
 
jkrCommented:
Actually, the values should be should be in seconds...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
yingchunliAuthor Commented:
Hi jkr,

I tried your function PlayFromTo(). As I ran the program, there was no sound at all. (I am sure the wav file is OK with wav file player).

I tried the following two ways, and they are all not working.
(1) mciSendString("Open test.wav type waveaudio alias sound", NULL, 0, NULL);
    mciSendString("Play sound from 15 to 25", NULL, 0, NULL);
(2) mciSendString("Play test.wav type waveaudio alias sound from 15 to 25", NULL, 0, NULL);

If I have a "test.wav" file, and I want to play the part from 15th to 25th second of it, what would be the exact C++ code that is working?



0
 
yingchunliAuthor Commented:
I have increase the points to 100 for a working answer.
0
 
yingchunliAuthor Commented:
I have increased the points to 150 for a working answer.
0
 
bcladdCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Deleted: Original question unanswered (and MSDN link fails)

Please leave any comments here within the next seven days. Experts: Silence
means you don't care.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

-bcl (bcladd)
EE Cleanup Volunteer
0
 
jkrCommented:
>>MSDN link fails

That is why I always post the full title of the articles also, to ensure they can be found even after MS restructured their site - the article is now available at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_command_strings.asp
0
 
jkrCommented:
Hm, apart from the MSDN link that still exists, the above code pretty much answers this Q...
0
 
jkrCommented:
Just for the record - *I* left my comments within the seven day period. And, just in case I wasn't clear enough, I'm objecting to a deletion :o)
0
 
jkrCommented:
Thank you (all)!
0
 
jkrCommented:
>> Thank you for answering the questions

Hum, the major return that I get from answering questions is as boring as important: Practise & rehearsal. And, some new thoughts and points of view, too.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now