First, open Rad Studio XE8, new project, add Components MediaPlayer, cameracomponent and some buttons, from top to next for Button1, 2, 3, 4, 5, 6, 7, 8;
Second, in the header file. h add:#include <fmx. Media.hpp>, and
__published:void __fastcall GetImage ();
Private
Taudiocapturedevice *microphone; Declaring a microphone
String FileName;
Third, write the code in each button:
Note that there is #include <System.IOUtils.hpp>in the. cpp file, and the remaining code is:
__fastcall Tform1::tform1 (tcomponent* owner) : Tform (owner)
{//Turn on the microphone device, locate the storage path
microphone=tcapturedevicemanager::current->defaultaudiocapturedevice;
Filename=includetrailingpathdelimiter (System::ioutils::tpath::gettemppath ()) + "MY.CAF";
}
void __fastcall Tform1::getimage () {//recognition camera recorded image
Cameracomponent1->samplebuffertobitmap (this->image1->bitmap,true);
}
void __fastcall Tform1::cameracomponent1samplebufferready (tobject *sender, const tmediatime ATime)
{
Tthread::synchronize (Tthread::currentthread,getimage); Calling the GetImage method
}
void __fastcall Tform1::button1click (tobject *sender)//Start recording
{
this->cameracomponent1->active=true;
}
void __fastcall Tform1::button2click (tobject *sender)//Stop Recording
{
this->cameracomponent1->active=false;
}
void __fastcall Tform1::button3click (tobject *sender)//Open Flash
{
this->cameracomponent1->torchmode=ttorchmode::modeon;
}
void __fastcall Tform1::button4click (tobject *sender)//Turn off Flash
{
this->cameracomponent1->torchmode=ttorchmode::modeoff;
}
void __fastcall Tform1::button5click (tobject *sender)//Start playback
{
this->mediaplayer1->filename=filename;
This->mediaplayer1->play ();
}
void __fastcall Tform1::button6click (tobject *sender)//Start recording
{
this->microphone->filename=filename; Get the storage directory for recordings
this->edit1->text=filename;
This->microphone->startcapture ();
}
void __fastcall Tform1::button7click (tobject *sender)//Stop playback
{
This->mediaplayer1->stop ();
}
void __fastcall Tform1::button8click (tobject *sender)//Stop Recording
{
This->microphone->stopcapture ();
}
Third, click on the Project.exe, right-click option, tick a few options to enable the Android platform to support media playback and recording, read and write user directory features:
Four, will realize the platform for Android, click to run, after installation on the phone to open, click Start Recording, you can see the edit box shows the table of contents, stop recording after the playback (the sound may be small, remember to adjust the volume), the video can switch the flash.
RAD Studio XE8 Cross-platform for recording and recording functions in the app