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?
 
yingkitConnect With a Mentor Commented:
use the built-in mediaplayer...
use mediaplayer1.play to play the wave
0
 
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
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
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
All Courses

From novice to tech pro — start learning today.