Tema: WaveOutOpen
Ver Mensaje Individual
  #4  
Antiguo 01-10-2010
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - Espańa
Posts: 18.331
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
He encontrado este código por Internet.
Ya te adelanto que no es mío y no lo he probado ya que en este equipo no dispongo del dispositivo adecuado.

Pruébalo y ya dirás...


Código Delphi [-]
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    TMS: TMemoryStream;
    wavOutDevice:Boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  MMSystem;


procedure TForm1.Button1Click(Sender: TObject);
begin
  {in some procedure}
  if wavOutDevice then begin
    PlaySound(TMS.Memory, 0, SND_ASYNC or SND_MEMORY);
  end;
  //add 'or SND_LOOP' to loop it
  //if others, use tmsBells.Memory, etc. instead
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  if WaveOutGetNumDevs = 0 then begin
    showmessage('No .wav output device available in your PC');
    wavOutDevice := False; //global boolean variable
  end
  else begin
    TMS := TMemoryStream.Create;
    //use next line else where to load other .wav files when you need them
    TMS.LoadFromFile('.\ding.wav'); //may need a path like 'audio\music.wav'
    wavOutDevice := True; //global boolean var
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  //turn off any sound, use this else where to do same
  PlaySound(NIL, 0, SND_ASYNC or SND_NODEFAULT);
  TMS.Free; //free memory for other app's
end;

end.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita