Solved

Record from mic using Delphi Mediaplayer

Posted on 2006-11-29
6
2,062 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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