Solved

Record from mic using Delphi Mediaplayer

Posted on 2006-11-29
6
2,026 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 4

Expert Comment

by:Meldrachaun
Comment Utility
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
Comment Utility

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now