// Variante 1:

// Getestet mit D4 unter XP

// So kann man Wav-Dateien überlappend abspielen. Bedingung ist, dass der Titel,
// der überlappt werden soll, länger ist, als die Überlappungszeit
(logisch).

uses mmsytem; 
 
const 
  z: word = 0; 
  ueberlappen: integer = 3500; // 3,5 Sekunden 
 
function SoundPlay(datei, alias: string): integer; 
var 
  r: array[0..29] of char; 
begin 
  MCISendString(pchar('open ' + datei + ' type waveaudio alias ' + alias), 
    nil, 0, 0); 
  MCISendString(pchar('set ' + alias + ' time format milliseconds'), nil, 0, 0); 
  result := MCISendString(pchar('status ' + alias + ' length'), r, 30, 0); 
  if result = 0 then result := strtoint(r) 
  else result := -1; 
  inc(z); 
  MCISendString(pchar('play ' + alias), nil, 0, 0); 
end; 
 
 
// Beispielaufruf für zwei Waves 
procedure TForm1.Button5Click(Sender: TObject); 
var 
  zeit: cardinal; 
  msek: integer; 
begin 
  msek := SoundPlay('C:\Funny\FR65E2.WAV', 'Titel' + inttostr(z)); 
  if msek > ueberlappen then begin 
    zeit := gettickcount - ueberlappen + msek; 
    repeat 
      application.processmessages; 
    until (gettickcount >= zeit) or Application.terminated; 
    SoundPlay('C:\Funny\KAHNSN.WAV', 'Titel' + inttostr(z)); 
  end; 
end; 


//------------------------------------------------------------

// Variante 2:
// Getestet mit
RS 10.4 unter W11 // So kann man Wav-Dateien zu beliebigen Zeitpunkten abspielen, // zeitlich versetzt, aber auch gleichzeitig.
uses Winapi.MMSystem; 
 
const 
  T1 = '"D:\WAVTEST\Musik.wav"'; 
  T2 = '"D:\WAVTEST\Glocken.wav"'; 
 
procedure MCICommand(Cmd: PChar); 
var 
  s: string; 
begin 
  s := extractfilename(Cmd); 
  if ansilastchar(s) = '"' then 
    s := Copy(s, 1, length(s) - 1); 
  if mciSendString(Cmd, nil, 0, 0) <> 0 then 
    Showmessage('Fehler bei ' + s); 
end; 
 
procedure TForm1.FormShow(Sender: TObject); 
begin 
  MCICommand('open waveaudio shareable'); 
end; 
 
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); 
begin 
  MCICommand('close waveaudio'); 
end; 
 
// Titel 1 abspielen 
procedure TForm1.Button1Click(Sender: TObject); 
begin 
  MCICommand('play ' + T1); 
end; 
 
// Titel 2 abspielen 
procedure TForm1.Button2Click(Sender: TObject); 
begin 
  MCICommand('play ' + T2); 
end; 
 
// Titel 1 beenden 
procedure TForm1.Button3Click(Sender: TObject); 
begin 
  MCICommand('close ' + T1); 
end; 
 
// Titel 2 beenden 
procedure TForm1.Button4Click(Sender: TObject); 
begin 
  MCICommand('close ' + T2); 
end;


 

Zugriffe seit 6.9.2001 auf Delphi-Ecke