Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to use the TMediaPlayer to record sound from a microphone Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Aug-02
Category
Multimedia
Language
Delphi 2.x
Views
112
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I'm trying to use MediaPlayer to record sound into a wave file through a 
microphone. Can someone show me some simple code to do the recording?

Answer:

The TMediaPlayer can only open a wave file that has at least one byte of data in 
it. I found this out when I tried to create and open a wave file that was nothing 
but a wave header. The TMediaPlayer wouldn't do it. The following code creates a 
wave file with a single byte of data at the beginning. It is a bit of a kludge to 
do it this way, but it works. You need to add MMSYSTEM to the uses clause of any 
unit that uses this function.


1   function CreateNewWave(NewFileName: string): Boolean;
2   var
3     DeviceID: Word;
4     Return: LongInt;
5     MciOpen: TMCI_Open_Parms;
6     MciRecord: TMCI_Record_Parms;
7     MciPlay: TMCI_Play_Parms;
8     MciSave: TMCI_SaveParms;
9     MCIResult: LongInt;
10    Flags: Word;
11    TempFileName: array[0..255] of char;
12  begin
13    MediaPlayer.Close;
14    StrPCopy(TempFileName, NewFileName);
15    MciOpen.lpstrDeviceType := 'waveaudio';
16    MciOpen.lpstrElementName := '';
17    Flags := Mci_Open_Element or Mci_Open_Type;
18    MCIResult := MciSendCommand(0, MCI_OPEN, Flags, LongInt(@MciOpen));
19    DeviceID := MciOpen.wDeviceId;
20    MciRecord.dwTo := 1;
21    Flags := Mci_To or Mci_Wait;
22    MCIResult := MciSendCommand(DeviceID, Mci_Record, Flags, LongInt(@MciRecord));
23    mciPlay.dwFrom := 0;
24    Flags := Mci_From or Mci_Wait;
25    MciSendCommand(DeviceId, Mci_Play, Flags, LongInt(@MciPlay));
26    mciSave.lpfileName := TempFilename;
27    Flags := MCI_Save_File or Mci_Wait;
28    MCIResult := MciSendCommand(DeviceID, MCI_Save, Flags, LongInt(@MciSave));
29    Result := MciSendCommand(DeviceID, Mci_Close, 0, LongInt(nil)) = 0;
30  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC