简体   繁体   中英

How to record audio from microphone input using TMediaPlayer in Delphi?

Hi I'm quite new to Delphi but have programmed before.

I want to record audio from a laptop's microphone input. Tmediaplayer has a record button but I can't quite understand the documentation from http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/MPlayer_TMediaPlayer_StartRecording.html on how to use it.

Could someone please list some steps on how to use it or link any example code where Tmediaplayer is used for recording?

Also what format is the recorded file saved? Can it be an array with the data within it or is it a .WAV file?

Any help appreciated and thanks.

Use is pretty simple, using the TMediaPlayer.OnClick event. This answer is based on the VCL.TMediaPlayer, as you've not specified which UI library you're using.

procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
  var DoDefault: Boolean);
begin
  case Button of
    btStop:
      begin
        MediaPlayer1.Stop;
        MediaPlayer1.FileName := 'WhateverYouWant.wav';
        MediaPlayer1.Save;
      end;
    btRecord: MediaPlayer1.StartRecording;
  end;

I've omitted the other buttons for brevity.

The file type is determined by the TMediaPlayer.DeviceType property, which has to be set before the recording is started. The only audio recording type I can see in the list is the WAV format.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM