Now I want to record a new wav. I use Close, assign a new file name, then
Open.
But after recording, when I play the new WAV it first plays my new
recording, then the old. How do I clear the MediaPlayer buffer to start a
fresh WAV?
Thanks,
Dan
The TMediaPlayer can only open a wave file that has at least one byte
of data in it. I found this out when I
tried to create and open a wave file that was nothing but a wave
header. The TMediaplayer wouldn't do it.
The following code creates a wave file with a single byte of data at
the beginning. It is a bit of a kludge
to do it this way, but it works. You need to add MMSYSTEM to the uses
clause of any unit that uses this
function --
function CreateNewWave(NewFileName: String): Boolean;
var
DeviceID: Word;
Return: LongInt;
MciOpen: TMCI_Open_Parms;
MciRecord: TMCI_Record_Parms;
MciPlay: TMCI_Play_Parms;
MciSave: TMCI_SaveParms;
MCIResult: LongInt;
Flags: Word;
TempFileName: array[0..255] of char;
begin
MediaPlayer.Close;
StrPCopy(TempFileName, NewFileName);
MciOpen.lpstrDeviceType := 'waveaudio';
MciOpen.lpstrElementName := '';
Flags := Mci_Open_Element or Mci_Open_Type;
MCIResult := MciSendCommand(0, MCI_OPEN, Flags,
LongInt(@MciOpen));
DeviceID := MciOpen.wDeviceId;
MciRecord.dwTo := 1;
Flags := Mci_To or Mci_Wait;
MCIResult := MciSendCommand(DeviceID, Mci_Record, Flags,
LongInt(@MciRecord));
mciPlay.dwFrom := 0;
Flags := Mci_From or Mci_Wait;
MciSendCommand(DeviceId, Mci_Play, Flags, LongInt(@MciPlay));
mciSave.lpfileName := TempFilename;
Flags := MCI_Save_File or Mci_Wait;
MCIResult := MciSendCommand(DeviceID, MCI_Save, Flags,
LongInt(@MciSave));
Result := MciSendCommand(DeviceID, Mci_Close, 0, LongInt(nil)) =
0;
end;
Nick Hodges
TeamB
Nick,
Thank you very much. I had concluded that including a blank WAV with my
program, and loading it before recording any new one was the solution -
yours is a better twist on that solution, because it doesn't require the
additional file, except at run-time.
I guess they should add a MediaPlayer1.Clear to Delphi 5. :-)
Thanks again,
Dan
>
>I guess they should add a MediaPlayer1.Clear to Delphi 5. :-)
>
Ahh, but _you_ can do that. Object-oriented programming is cool,
huh? <g>
Nick Hodges
TeamB