Author: Tomas Rutkauskas
I'd like to have a background.wav file playing and once in a while have a short
effects .wav sound play at the same time (without interrupting - stopping and
restarting it - the background .wav).
Answer:
The Delphi code below plays two sounds concurrently under Win95. I think concurrent
sound playing relies on the driver supporting multiple inputs, and I believe you
could request if it has this capability before trying to play.
1 procedure TForm1.Button1Click(Sender: TObject);
2 begin3 SendMCICommand('open waveaudio shareable');
4 SendMCICommand('play hickory.wav');
5 SendMCICommand('play greeting.wav');
6 SendMCICommand('close waveaudio');
7 end;
8 9 procedure TForm1.SendMCICommand(Cmd: string);
10 var11 RetVal: integer;
12 ErrMsg: array[0..254] of char;
13 begin14 RetVal := mciSendString(StrAsPChar(Cmd), nil, 0, 0);
15 if RetVal <> 0 then16 begin17 {get message for returned value}18 mciGetErrorString(RetVal, ErrMsg, 255);
19 MessageDlg(StrPas(ErrMsg), mtError, [mbOK], 0);
20 end;
21 end;
22 23 function StrAsPChar(var S: OpenString): PChar;
24 {returns a PChar from a string}25 begin26 if Length(S) = High(S) then27 dec(S[0]);
28 S[Ord(Length(s)) + 1] := #0;
29 Result := @S[1];
30 end;