Solved

how to play wav files

Posted on 2006-06-23
6
1,612 Views
Last Modified: 2013-11-17
what I need to write wave player program.
I need to open a wave file and play it in my appl.

0
Comment
Question by:tigrisek
  • 2
  • 2
6 Comments
 
LVL 11

Accepted Solution

by:
Jase-Coder earned 125 total points
ID: 16968966
use the media component or use the function PlaySound()

for example: PlaySound("MyWave.wav", NULL, SND_SYNC);
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 16968981
in the properties windows for the media control you can set the filename and in your code you can do:

myPlayer.Play();
0
 
LVL 18

Assisted Solution

by:JoseParrot
JoseParrot earned 125 total points
ID: 16977602
Hi,

With a Form in your IDE, go to tab System, then click MediaPlayer (icon is a yellow musical note over a film strip).
Then click in the Form. Now you have the controls of your Wave Player. In Object Inspector, default DeviceType should be dtAutoSelect.

You need now a dialog to open the wave files and read them from disk or CD.
Go to tab Dialogs and click in OpenDialog. In its Object Inspector, DefaultExt is .wav, and Filter is Wave and #.wav.

Create a Button in the form. By doubleclicking in the button, the edit window opens in the right point where to write the code for what you want when the button is clicked. Then type:
     OpenDialog1->Execute();
This will open the dialog for file selection. Only wav filies will appear in the dialog.

Now, associate the file name to the MediaPlayer component.
To do that, type
    MediaPlayer1->FileName = OpenDialog1->FileName;

Optionally, tell your MediaPlayer to play the music, instead of waiting for the user click in the control.
    MediaPlayer1->Open();
In this case, you can set MediaPlayer not visible.

Your code will be:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
OpenDialog1->Execute();
MediaPlayer1->FileName = OpenDialog1->FileName;
Edit1->Text=OpenDialog1->FileName; // optional to show what music is playing
MediaPlayer1->Open();
//MediaPlayer1->Play(); // if you want to play automatically
}

Not complicated with great Borland C++ Builder.

Jose
0
 
LVL 18

Expert Comment

by:JoseParrot
ID: 16977612
Please, a correction:
    MediaPlayer1->Open();        is mandatory.

    MediaPlayer1->Play();          is optional.

Even Microsoft has Service Packs...

Jose
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

809 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