How to play wave when we click that button????

Hi,.
  i want to ask how i can play wav file when i click certain button using delphi 5???
another question is how to place the created image (jpg) in the center of the form?? i mean the image will stay in the center after i click the minimize button at the top of right hand site.
smile22Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yingkitCommented:
use the built-in mediaplayer...
use mediaplayer1.play to play the wave
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yingkitCommented:
Not really know what do you want in the second question.
0
RBertoraCommented:
Use a TMediaPlayer component (system palette) to play wav files


in your button click use:
MediaPlayer1.FileName := 'c:/mywav.wav';
MediaPlayer1.Play;


Rob ;-)
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

RBertoraCommented:
For your second question:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls,jpeg, ExtDlgs;

type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCanResize(Sender: TObject; var NewWidth,
      NewHeight: Integer; var Resize: Boolean);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.FormCanResize(Sender: TObject; var NewWidth,
  NewHeight: Integer; var Resize: Boolean);
begin
  Image1.Left := Form1.Width div 2 - Image1.Width div 2;
  Image1.Top := Form1.Height div 2 - Image1.Height div 2;
end;

procedure TForm1.FormActivate(Sender: TObject);

var
  MyJPG : TJPegImage;
begin
  MyJPG := TJpegImage.Create;
  MyJpg.LoadFromFile('c:\chemical.jpg');
  Image1.Picture.Bitmap.Assign(MyJPG);
  MyJpg.Free;
end;

end.


Rob ;-)
0
polux12Commented:
The simpliest way to play wav file is
sndPlaySound function (from MMSystem unit). The use is:
sndPlaySound(filename: PChar,flags:Word) : boolean;
Don't forget to add MMSystem in your uses clause...
filename - valid wav file name;
flags - taken from MMSystem.hlp:
SND_SYNC

The sound is played synchronously and the function does not return until the sound ends.

SND_ASYNC

The sound is played asynchronously and the function returns immediately after beginning the sound. To terminate an asynchronously-played sound, call sndPlaySound with lpszSoundName set to NULL.

SND_NODEFAULT

If the sound can't be found, the function returns silently without playing the default sound.

SND_MEMORY

The parameter specified by lpszSoundNamepoints to an in-memory image of a waveform sound.

SND_LOOP

The sound will continue to play repeatedly until sndPlaySound is called again with the lpszSoundName parameter set to NULL. You must also specify the SND_ASYNC flag to loop sounds.

SND_NOSTOP

If a sound is currently playing, the function will immediately return FALSE without playing the requested sound.

---------------------------------
About the image:
procedure TForm1.FormCanResize(Sender: TObject; var NewWidth,
  NewHeight: Integer; var Resize: Boolean);
begin
  Image1.Left := Width div 2 - Image1.Width div 2;
  Image1.Top := Height div 2 - Image1.Height div 2;
end;

0
AlphomegaCommented:
in onclick event, use function

function PlayWave(WaveFile: string);
begin
var
  PWaveFile : Array[0..250] of Char;
begin
  if (UpperCase(ExtractFileExt(WaveFile)) = '.WAV') and (Length(WaveFile) <= 250) then
  begin
    StrPCopy(PWaveFile, WaveFile);
    try
      sndPlaySound(PWaveFile,  SND_ASYNC);
    finally
      // Do nothing
    end;
  end;
end;
0
smile22Author Commented:
Hi Yingkit,........
 i already read your answer but when i try it i still facing the same problem.
the problem is the image and the component like button,picture which is inside the image are still move away from the setting place, when i click the minimize button.
how can i make it to the place which is i want to??

About the playing wav??
i don't want to play it with media player....
i want is when i click one button, the sound will come out......
i need all this to make my presentation........
0
smile22Author Commented:
Hi Yingkit,........
 i already read your answer but when i try it i still facing the same problem.
the problem is the image and the component like button,picture which is inside the image are still move away from the setting place, when i click the minimize button.
how can i make it to the place which is i want to??

About the playing wav??
i don't want to play it with media player....
i want is when i click one button, the sound will come out......
i need all this to make my presentation........
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.