Table des matières

Les Sons dans Lazarus

MMSystem

uses MMSystem;
...
 
sndPlaySound('C:\sounds\test.wav',0,snd_Async or snd_NoDefault or Snd_Loop););
1. En créant un fichier ressource (monfichier.res).
 
{$R monfichier.RES} // Ton fichier ressource
 
Sons1 WAV "Data.wav"
Sons2 RCDATA "bronze.mp3"
 
Var
dirdir : string;
 
procedure TFmMain.BplayClick(Sender: TObject);
var
  hres: THandle;
  pres: PChar;
begin
 // cherche le son représentant Data.wav soit sons1
 
  hres := FindResource(hInstance, pchar('Sons1'), 'wav');
  if hRes <> 0 then
 
//si trouvé alors
 
  begin
  hres := LoadResource(hInstance, hres);
 
 //charge le son
 
  pres := LockResource(hres);
 
 //joue le son en boucle ajouter SND_LOOP
 
  sndPlaySound(pres, SND_SYNC or SND_LOOP or SND_MEMORY);
  UnLockResource(hres); FreeResource(hres);
 
 
 
end;
end;

Sources & Ressources