Results:
1. When you add an action in actionlist, you need to skip to the Master interface and not the Android4phonel interface.
2. If the permission is not turned on, the device does not support stop recording operation (record Audion is changed to true).
3. The effect of playback is to play once and stop. is not circular.
Instance code:
1 UnitUnit1;2 3 Interface4 5 uses6 system.sysutils, System.types, System.uitypes, system.classes, System.variants,7 FMX. Types, FMX. Controls, FMX. Forms, FMX. Graphics, FMX. Dialogs, Fmx.stdctrls,8 FMX. Controls.presentation, System.actions, FMX. Actnlist, FMX. Media;9 Ten Const OneAudio_filename ='Test.mp3';//file name saved by recording A - type -TForm1 =class(Tform) the Button1:tbutton; - Button2:tbutton; - Button3:tbutton; - Button4:tbutton; + Label1:tlabel; - Label2:tlabel; + actionlist1:tactionlist; A acstartrecording:taction; at acstoprecording:taction; - acplay:taction; - acstop:taction; - Mediaplayer1:tmediaplayer; - procedureActionlist1update (action:tbasicaction;varHandled:boolean); - procedureAcstartrecordingexecute (sender:tobject); in procedureAcstoprecordingexecute (sender:tobject); - procedureformcreate (sender:tobject); to procedureAcplayexecute (sender:tobject); + procedureAcstopexecute (sender:tobject); - Private the {Private Declarations} * Public $ Fmicrophone:taudiocapturedevice;Panax Notoginseng functionHasmicrophone:boolean; - functionIsmicrophonerecording:boolean; the {Public Declarations} + End; A the var + Form1:tform1; - $ Implementation $ uses -System. Ioutils;//need to introduce - {$R *.FMX} the {$R *. NMXHDPIPH.FMX ANDROID} - Wuyi //get the recording file save path for different platforms the functionGetaudiofilename (ConstAfilename:string):string; - begin Wu {$IFDEF ANDROID} -Result: = Tpath.gettemppath +'/'+Afilename; About {$ELSE} $ {$IFDEF IOS} -Result: = Tpath.gethomepath +'/documents/'+Afilename; - {$ELSE} -Result: =Afilename; A {$ENDIF} + {$ENDIF} the End; - $ procedureTform1.acplayexecute (sender:tobject); the begin the ifIsmicrophonerecording Then //If you are recording, stop recording first the Acstoprecording.execute; the //The following plays the recording file Audio_filename -Mediaplayer1.filename: =Getaudiofilename (audio_filename); in Mediaplayer1.play; the End; the About procedureTform1.acstartrecordingexecute (sender:tobject); the begin theAcstop.execute;//Select Stop Recording the ifHasmicrophone Then + begin - //ready to save the recording to the file ' Test.mp3 ' theFmicrophone.filename: =Getaudiofilename (audio_filename);Bayi Try theFmicrophone.startcapture;//Start Recording the except -ShowMessage ('the device does not support recording operations. '); - End; the End the Else theShowMessage ('There is no microphone device. '); the End; - the procedureTform1.acstopexecute (sender:tobject); the begin the Mediaplayer1.stop;94 End; the the procedureTform1.acstoprecordingexecute (sender:tobject); the begin98 ifIsmicrophonerecording Then //If you are recording About Try -Fmicrophone.stopcapture;{Stop Recording}101 except102ShowMessage ('the device does not support the stop recording operation. ');103 End;104 End; the 106 procedureTform1.actionlist1update (action:tbasicaction;varHandled:boolean);107 begin108 //Judging the visibility of a picture109 Case(Hasmicrophone and(fmicrophone.state = tcapturedevicestate.capturing)) of theTrue:Label2.Text: ='recording';111False:Label2.Text: ='Stop Recording'; the End;113 //determine if the 4 buttons can be pressed theAcstartrecording.enabled: = notIsmicrophonerecording andHasmicrophone; theAcstoprecording.enabled: =ismicrophonerecording; theacstop.enabled: = Assigned (Mediaplayer1.media) and(Mediaplayer1.state =117 tmediastate.playing);118acplay.enabled: = FileExists (Getaudiofilename (audio_filename)) and119(Mediaplayer1.state <>tmediastate.playing); - End;121 122 proceduretform1.formcreate (sender:tobject);123 begin124 //initializing the recording device theFmicrophone: =TCaptureDeviceManager.Current.DefaultAudioCaptureDevice;126 End;127 - //determine if there is a microphone129 functionTForm1.HasMicrophone:Boolean; the begin131Result: =Assigned (fmicrophone); the End;133 134 //determine if the recording135 functionTForm1.IsMicrophoneRecording:Boolean;136 begin137Result: = Hasmicrophone and(Fmicrophone.state =tcapturedevicestate.capturing);138 End;139 $ End.
Android instance-recording and playback (play MP3) (xe8+ Xiaomi 2)