Toon posts:

[Delphi] Geluid afspelen

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hallo mede tweakers,

Ik wil in mijn programma een geluidje afspelen, als er op een knop gedrukt wordt (net zo'n "ping" als in Windows).
Ik kan gewoon een TMediaPlayer gebruiken. Maar dan moet ik weer heel component in mijn programma zetten,
terwijl ik meer als de helft niet gebruik.

Is er geen andere manier om simpel een geluidje af te spelen?

Alvast bedankt

  • Knutselsmurf
  • Registratie: December 2000
  • Laatst online: 01-09 17:40

Knutselsmurf

LED's make things better

Kijk eens naarde API-functie Playsound

- This line is intentionally left blank -


Verwijderd

Topicstarter
Ik heb op de MSDN CD gezocht en gevonden.

Maar als ik PlaySound(''); gebruik,
dan kent ie de functie niet, er staat ook verder niet bij of ik iets moet includen ofzo.

Weet iemand misschien meer ?

  • BM
  • Registratie: September 2001
  • Laatst online: 21:12

BM

Admin Softe Goederen
Volgens MSDN:
The PlaySound function allows you to specify a sound in one of three ways:

As a system alert, using the alias stored in the WIN.INI file or the registry
As a filename
As a resource identifier
PlaySound("test.wav")
zoiets zou dan toch moeten werken? :?
Anders ShellApi ff toevoegen aan je uses list?

Xbox
Even the dark has a silver lining


Verwijderd

Topicstarter
Helaas, werk niet. Ik heb ook ShellApi toegevoegd, maar dat helpt ook niet :(

[Error] fMain.pas(770): Undeclared identifier: 'PlaySound'

Verwijderd

Je moet de unit MMSystem toevoegen aan je uses.

Verwijderd

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
1) Declare this function and THandle var in the form's or object's
private section:

  private
    { Private declarations }
    DLLHandle : THandle; {Handle to the DLL}
    PlaySound : function (lpszSoundName: PChar; uFlags: Word): Bool;


Then you need to load the  MSYSTEM.DLL  (dynamic link library) into
memory:


2) Include the MMSystem unit in your form's uses statement:

{$R *.DFM}
uses Main, MMSystem;

3) In the Form's FormCreate handler, load the library into memory:

procedure TSplashForm.FormCreate(Sender: TObject);
begin
{make sure mmsystem.dll exists before calling sndPlaySound}
DLLHandle := LoadLibrary('mmsystem.dll');
if DLLHandle >= 32 then
  @PlaySound := GetProcAddress(DLLHandle, 'sndPlaySound');
end;


4) Play the .WAV file !!!

procedure TSplashForm.FormShow(Sender: TObject);
const
  snd_Async           = $0001;  { play asynchronously }
begin
PlaySound('c:\sfsdbase\motstart.wav', snd_ASync);
end;

This example is a splash form, that plays a wav file for the duration
of it's presence.  It does so n the FormShow event.

You could of course play it however you want at this point..

Hope that helps!


Succes
Pagina: 1