Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TMediaPlayer - Clearing the WAV

96 views
Skip to first unread message

Dan Veaner

unread,
Feb 9, 1999, 3:00:00 AM2/9/99
to
I have played a WAV file using a TMediaPlayer component.

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

Nick Hodges (TeamB)

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
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

Dan Veaner

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
Nick Hodges (TeamB) wrote in message
<36c17023....@forums.borland.com>...

>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.

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

Nick Hodges (TeamB)

unread,
Feb 13, 1999, 3:00:00 AM2/13/99
to
On Wed, 10 Feb 1999 09:05:35 -0500, "Dan Veaner" <da...@emmasoft.com>
wrote:

>
>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

0 new messages