?
Solved

Use mciSendString to play wav file

Posted on 2003-02-24
14
Medium Priority
?
1,142 Views
Last Modified: 2008-02-01
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
Comment
Question by:yingchunli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
14 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 8010100
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
 

Author Comment

by:yingchunli
ID: 8010298
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
 
LVL 86

Expert Comment

by:jkr
ID: 8010750
Actually, the values should be should be in seconds...
0
Independent Software Vendors: 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!

 

Author Comment

by:yingchunli
ID: 8027554
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
 

Author Comment

by:yingchunli
ID: 8061040
I have increase the points to 100 for a working answer.
0
 

Author Comment

by:yingchunli
ID: 8083140
I have increased the points to 150 for a working answer.
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9784392
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
 
LVL 86

Accepted Solution

by:
jkr earned 600 total points
ID: 9784414
>>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
 
LVL 86

Expert Comment

by:jkr
ID: 9789484
Hm, apart from the MSDN link that still exists, the above code pretty much answers this Q...
0
 
LVL 86

Expert Comment

by:jkr
ID: 9827745
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
 
LVL 86

Expert Comment

by:jkr
ID: 9829067
Thank you (all)!
0
 
LVL 86

Expert Comment

by:jkr
ID: 9829156
>> 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question