Solved

Record from mic using Delphi Mediaplayer

Posted on 2006-11-29
6
2,142 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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