how to play wav files

what I need to write wave player program.
I need to open a wave file and play it in my appl.

tigrisekAsked:
Who is Participating?
 
Jase-CoderConnect With a Mentor Commented:
use the media component or use the function PlaySound()

for example: PlaySound("MyWave.wav", NULL, SND_SYNC);
0
 
Jase-CoderCommented:
in the properties windows for the media control you can set the filename and in your code you can do:

myPlayer.Play();
0
 
Jose ParrotConnect With a Mentor Graphics ExpertCommented:
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
 
Jose ParrotGraphics ExpertCommented:
Please, a correction:
    MediaPlayer1->Open();        is mandatory.

    MediaPlayer1->Play();          is optional.

Even Microsoft has Service Packs...

Jose
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.