Solved

Record from mic using Delphi Mediaplayer

Posted on 2006-11-29
6
2,076 Views
Last Modified: 2008-01-09
I'm trying to record from the mic using the Delphi Mediaplayer component.

All existing answers to this question point to a link called:

http://www.bhnet.com.br/~simonet/howtoprojs.htm

which does not work!

Any suggestions/code examples?

Thanks

JonathanH13
0
Comment
Question by:JonathanH13
6 Comments
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 18038412
Do you first have to create a blank .wav file and link it to the mediaplayer.
Then when the application starts, mediaplayer.open to open the file, then just press the record button and talk?
Never used it so Im just guessing.
Might even have to move back to the beginning of the file once finished recording.
0
 

Author Comment

by:JonathanH13
ID: 18038545
Yeah, that's the idea, but it's not so straightforward. What I have so far:

procedure TForm1.Button1Click(Sender: TObject);
begin
    Timer1.Enabled:=True;

    MediaPlayer1.FileName := 'c:\Test.Wav';
    MediaPlayer1.Open;
    MediaPlayer1.StartRecording;

end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
 MediaPlayer1.Stop;
 Label1.Caption:='End';
end;

But this does not work, and I'm not sure why...
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 18039338
Yeah Im not getting it to work either.
Must be something really obvious Im missing but this isnt something I normally play around with.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Expert Comment

by:Meldrachaun
ID: 18040389
Is this the know bug with TMediaPlayer?

http://qc.borland.com/wc/qcmain.aspx?d=5475
http://bdn.borland.com/article/16427

One thing you might try.  I haven't used it, but it looks like there's a JEDI version of Apple's QuickTime components.  You might be able to record with that...

http://www.delphi-jedi.org/
0
 
LVL 9

Accepted Solution

by:
bernani earned 300 total points
ID: 18059709

Hi,

You can't record in Delphi using MP.Startrecording but you can assign a procedure for the MP record button to do it

Use .... MMSystem;

...

// recording .... Stereo 44KHz 16Bits
procedure TForm1.btnRecordClick(Sender: TObject);
begin
mciSendString('OPEN NEW TYPE WAVEAUDIO ALIAS mySound',nil,0,Handle);
mciSendString('SET mySound ' +
                   'TIME FORMAT MS ' +
                   'BITSPERSAMPLE 16 ' +
                   'CHANNELS 2 ' +
                   'SAMPLESPERSEC 44100 ' +
                   'BYTESPERSEC 176400 ' +
                   'ALIGNMENT 4',
                   nil,0,handle);
mciSendString('RECORD mySound',nil,0,Handle);
end;

// stop recording and save as "The Name of the file recorded.wav".

procedure TForm1.btnStopandSaveClick(Sender: TObject);
begin
mciSendString('STOP mySound',nil,0,Handle);
mciSendString('SAVE mySound "The Name of the file recorded.wav"',nil,0,Handle);
mciSendString('CLOSE mySound',nil,0,Handle);
end;

Hope this can help.





0
 

Author Comment

by:JonathanH13
ID: 18067485
bernani,

Yeah, that works. Thanks!

I found a way of getting around the problem by simply copying a blank audio file, in order to create a new file for recording:

FromFile := TFileStream.Create('Audio\Blank.wav', fmOpenRead);
    ToFile := TFileStream.Create('Audio\'+NameString+'.wav', fmCreate);
    ToFile.CopyFrom(FromFile, FromFile.Size);
    ToFile.Free;
    FromFile.Free;

Thanks Meldrachaun  for the useful overview, but I could not get the workaround in http://qc.borland.com/wc/qcmain.aspx?d=5475 to function properly.

Cheers,
JonathanH13
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question