smile22
asked on
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not really know what do you want in the second question.
Use a TMediaPlayer component (system palette) to play wav files
in your button click use:
MediaPlayer1.FileName := 'c:/mywav.wav';
MediaPlayer1.Play;
Rob ;-)
in your button click use:
MediaPlayer1.FileName := 'c:/mywav.wav';
MediaPlayer1.Play;
Rob ;-)
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(Sende r: 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:\che mical.jpg' );
Image1.Picture.Bitmap.Assi gn(MyJPG);
MyJpg.Free;
end;
end.
Rob ;-)
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(Sende
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
var
MyJPG : TJPegImage;
begin
MyJPG := TJpegImage.Create;
MyJpg.LoadFromFile('c:\che
Image1.Picture.Bitmap.Assi
MyJpg.Free;
end;
end.
Rob ;-)
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(Sende r: 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;
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(Sende
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;
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;
function PlayWave(WaveFile: string);
begin
var
PWaveFile : Array[0..250] of Char;
begin
if (UpperCase(ExtractFileExt(
begin
StrPCopy(PWaveFile, WaveFile);
try
sndPlaySound(PWaveFile, SND_ASYNC);
finally
// Do nothing
end;
end;
end;
ASKER
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........
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........
ASKER
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........
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........