[Android] Как записать видео с помощью стандартной программы?
uses
{...}, System.Messaging {TMessageManager}, Androidapi.JNI.GraphicsContentViewText;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
procedure HandleActivityMessage(const Sender: TObject; const M: TMessage);
function OnActivityResult(RequestCode, ResultCode: Integer; Data: JIntent): Boolean;
public
FMessageSubscriptionID: Integer;
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
uses
System.IOUtils, Androidapi.JNI.Os, Androidapi.JNI.App, Androidapi.JNI.Net,
Androidapi.JNIBridge, Androidapi.Helpers, Androidapi.JNI.JavaTypes,
Androidapi.JNI.Provider;
const
RECORD_VIDEO = 9;
procedure TForm1.Button1Click(Sender: TObject);
var
VideoIntent: JIntent;
videoUri: Jnet_Uri;
AFile: JFile;
FileName: TFileName;
begin
FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage(
TMessageResultNotification, HandleActivityMessage);
VideoIntent := TJIntent.JavaClass.init(
TJMediaStore.JavaClass.ACTION_VIDEO_CAPTURE);
if VideoIntent.resolveActivity(SharedActivityContext.getPackageManager()) <> nil then
begin
// см. /storage/sdcard0/Documents
FileName := TPath.Combine(TPath.GetSharedDocumentsPath, 'recording.mp4');
AFile := TJFile.JavaClass.init(StringToJString(FileName));
videoUri := TJnet_Uri.JavaClass.fromFile(AFile);
VideoIntent.putExtra(TJMediaStore.JavaClass.EXTRA_OUTPUT,
TJParcelable.Wrap((videoUri as ILocalObject).GetObjectID));
SharedActivity.startActivityForResult(VideoIntent, RECORD_VIDEO);
end;
end;
procedure TForm1.HandleActivityMessage(const Sender: TObject;
const M: TMessage);
begin
if M is TMessageResultNotification then
OnActivityResult(
TMessageResultNotification(M).RequestCode,
TMessageResultNotification(M).ResultCode,
TMessageResultNotification(M).Value);
end;
function TForm1.OnActivityResult(RequestCode, ResultCode: Integer;
Data: JIntent): Boolean;
begin
Result := False;
TMessageManager.DefaultManager.Unsubscribe(
TMessageResultNotification, FMessageSubscriptionID);
FMessageSubscriptionID := 0;
if RequestCode = RECORD_VIDEO then
begin
if ResultCode = TJActivity.JavaClass.RESULT_OK then
begin
TThread.Queue(nil, procedure
begin
Label1.Text := 'recording completed';
Invalidate;
end);
end;
end;
end;
|