HennaCode
HennaCode

Reputation: 61

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.

Upvotes: 2

Views: 3352

Answers (1)

Ken White
Ken White

Reputation: 125728

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.

Upvotes: 3

Related Questions