The first Andriod program was developed today to test recording and playback functions. The source code is copied online.
Code:
Unit Unit2;
Interface
Uses
System.sysutils, System.types, System.uitypes, system.classes, System.variants,
FMX. Types, FMX. Controls, FMX. Forms, FMX. Graphics, FMX. Dialogs, Fmx.stdctrls,
FMX. Media, System.ioutils;
Type
TForm2 = Class (Tform)
Btnstartrecord:tbutton;
Btnstoprecord:tbutton;
Imgon:tlabel;
Btnplay:tbutton;
Procedure Btnstartrecordclick (Sender:tobject);
Procedure Btnstoprecordclick (Sender:tobject);
Procedure Formcreate (Sender:tobject);
Procedure Btnplayclick (Sender:tobject);
Private
{Private declarations}
Public
{Public declarations}
End
Var
Form2:tform2;
Fmicrophone:taudiocapturedevice;
Implementation
{$R *.FMX}
Procedure Tform2.btnplayclick (sender:tobject);
var
A:tmediaplayer;
Begin
A: = Tmediaplayer.create (self);
Try
a.filename: = Tpath.gethomepath + '/recordtest.3gp ';
a.play
finally
Freeandnil (a);
END;
End;
Procedure Tform2.btnstartrecordclick (sender:tobject);
//Start recording
Begin
Fmicrophone: = TCaptureDeviceManager.Current.DefaultAudioCaptureDevice;
If Assigned (fmicrophone) then
BEGIN
fmicrophone.filename: = Tpath.gethomepath + '/recordtest.3gp ';
try
fmicrophone.startcapture;
imgon.visible: = True;
except
on E:exception do
BEGIN
imgon.visible: = False;
showmessage (' device is not recognized or not supported. ' + e.message);
end
end;
End
Else
showmessage (' no microphones available. ‘);
End;
Procedure Tform2.btnstoprecordclick (Sender:tobject);
Stop Recording
Begin
If Assigned (Fmicrophone) Then
Try
If fmicrophone.state = Tcapturedevicestate.capturing Then
Begin
Fmicrophone.stopcapture;
Imgon.visible: = False;
End
Except
Imgon.visible: = False;
ShowMessage (' equipment is not recognized or not supported ');
End
End
Procedure Tform2.formcreate (Sender:tobject);
Begin
Imgon.visible: = False;
End
End.
Several questions:
1. Release: Project->deployment, click on deploy to do it. Can produce an apk file, through QQ transmission to the phone, you can install and run, good magic.
2. Runtime prompt: Setaudiosource failed, on-line check the next, found to be a permission problem,
In the Androidmanifest.xml file, add:
<uses-permission
Android:name= "Android.permission.RECORD_AUDIO" >
</uses-permission>
3.230 on the DELPHI7 has been running a problem, has not been resolved before, a compilation error, after the online check, delete hkey_current_user\software\embarcadero\bds\15.0 on it.
4. Home testing, the XE7 has been unable to display the connection of the phone, and later changed to a connection line on it, depressed.
20160113 First Andriod Development log