delphi android 录像,delphi - Record video from camera on Android to mp4 - Stack Overflow

See the following docwiki for an answer (sort-of).

Of course the word "capturing" here means, getting the video input and putting it on the display. "Recording" means joining the frames together to make a movie file.

The following code was kindly provided to me by the people at

flashavconverter and is posted here with their approval:

uses

Androidapi.JNI.GraphicsContentViewText;

const

RECORD_VIDEO = 9;

implementation

uses

System.IOUtils,

Androidapi.JNI.Provider,

Androidapi.JNI.App,

Androidapi.JNI.Net,

Androidapi.JNIBridge,

Androidapi.Helpers,

Androidapi.JNI.JavaTypes,

Androidapi.JNI.Os;

{$R *.fmx}

procedure TFormMain.btnRecordClick(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

FileName := TPath.Combined(

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 TFormMain.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 TFormMain.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

lable1.Text:='recording completed';

Invalidate;

end);

end;

end;

end;

This code is a (near) complete answer to the question. The device-specific video recorder UI is launched for the user to interact with. There is no programmatic control other than the name of the file that the recording is saved to. As a Delphi developer who is overwhelmed by the Android API, I am grateful for this solution.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值