[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

Sound

can you give me an idea of how to make a button when I click it will make a short sound whether it's a wave or a midi sound? (include the source code or any homepage to refer to)
0
lewis_loo
Asked:
lewis_loo
  • 5
  • 3
1 Solution
 
rwilson032697Commented:
You can use a Resource File o hold the wave to play... Create a file with a .RC extension and compile it with the BRCC32 program.

    Example MYWAV.RC:
    1 WAVE C:\wav\welcome.wav


    Compile it with BRCC32 MYWAV.RC
    This will generate a .RES file for you. Include this in your program with {$R mywav.res }

    You can then play the sound with this line in the Button OnClick event:

    PlaySound(pchar('1'), HInstance, SND_RESOURCE|SND_SYNC);

Cheers,

Raymond.
0
 
IndefreiCommented:
unit Musikplayer1;

interface

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

type
  TForm1 = class(TForm)
    MusikCheck: TCheckBox;
    ListBox1: TListBox;
    Timer1: TTimer;
    MediaPlayer1: TMediaPlayer;
    procedure FormCreate(Sender: TObject);
    procedure FindFile(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure MusikCheckClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private-Deklarationen }

  public
    { Public-Deklarationen }

  end;

var
  Form1: TForm1;
  myExt : string;
  PathFileName,Path, FileName : String;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
    PathFileName :='C:\win95\media\*.*';
    MyExt:='.Wav';
    FindFile(Form1);
    PathFileName :='C:\Programme\Creative\Ctsnd\Samples\*.*';
   PathFileName :='C:\Mymedia\*.*';
    MyExt:='.MID';
    FindFile(Form1);
    Mediaplayer1.autoOpen := true;
    mediaplayer1.DeviceType:=dtAutoSelect;
    MediaPlayer1.FileName :=ListBox1.Items.Strings[random(ListBox1.Items.Count - 1)];
    mediaplayer1.open;
    MusikCheckClick(form1);

end;

procedure TForm1.FindFile(Sender: TObject);
var
        srec : TSearchRec;
begin
       Path := ExtractFilePath(PathFileName);
       FileName := ExtractFileName(PathFileName);

       if findfirst(PathFileName,faanyfile,srec) = 0 then
       begin
         repeat
           If Not(srec.attr and fadirectory > 0) then
           begin
              if ExtractFileExt((Srec.Name))= myExt then
              begin
                    ListBox1.Items.Add(path + Srec.Name);
              end;

           end;
         Until findnext(srec) <> 0;
       end;
       FindClose(SRec);
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
    Timer1.Interval := 100;
    Timer1.Enabled := True;

    case Mediaplayer1.mode of

    mpPlaying :
     begin
        Timer1.Enabled := True;
     end;
    mpStopped :
     begin
        Mediaplayer1.Close;
        MediaPlayer1.FileName :=ListBox1.Items.Strings[random(ListBox1.Items.Count - 1)];
        Mediaplayer1.open;
        Mediaplayer1.play;
     end;
    end;
end;

procedure TForm1.MusikCheckClick(Sender: TObject);
begin
     If MusikCheck.State = cbchecked Then
     begin
          Timer1Timer(form1);
     end
     else
     begin
          Timer1.enabled:=false;
          mediaplayer1.Stop;
     end;    
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
    Timer1.enabled:=false;
    mediaplayer1.Stop;
    Mediaplayer1.Close;
end;

end.
0
 
IndefreiCommented:
Oops
>> PathFileName :='C:\Programme\Creative\Ctsnd\Samples\*.*';
too much, eliminate it
Indi
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
lewis_looAuthor Commented:
do you all have any suggestion of how to play gif animator under Delphi
0
 
IndefreiCommented:
lewis_loo,
That's another question...
0
 
lewis_looAuthor Commented:
can you give in more detail step by step ? (I am the beginnner)
is BRCC32 is on Borland C++? then how can I use in Delphi
0
 
IndefreiCommented:
The bcc32.exe is in
\program files\borland\delphi\bin
to compile see Raymond's answer

the method using a tmediaplayer is completely different to Raymonds solution.

My sample just plays all soundfiles of the given directory
randomly one after the other

To play simply one sound on buttomClick
Put a Buttom from the "standard" component palette
and a mediaplayer from the "system" component palette
on to your form

In the event table of your button  doubleclick on the editfield
OnClick and you get

procedure TForm1.Button1Click(Sender: TObject);
begin
// write
     Mediaplayer1.play;
end;
In the event table of your form doubleclick on the editfield
OnCreate and

procedure TForm1.FormCreate(Sender: TObject);
begin
// write
    Mediaplayer1.autoOpen := true;
    mediaplayer1.DeviceType:=dtAutoSelect;
    MediaPlayer1.FileName :='C:\Mywav\Welcome.wav';
    mediaplayer1.open;
end;
and close the mediaplayer in
OnDestroy
procedure TForm1.FormDestroy(Sender: TObject);
begin
// write
    Mediaplayer1.Close;
end;

Well, Raymond
hope, you'll forgive me, that i post this as a new answer
cheers
Indi
0
 
IndefreiCommented:
of course BRCC32.exe
0
 
lewis_looAuthor Commented:
Thanks for your help
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now