[英]How can i retrieve the thumbnails of a video from an android device in a Delphi 10.3 platform?
In a mobile app developed under Delphi 10.3, i want to display the thumbnail of the video i'm picking from the local storage of the device.在 Delphi 10.3 下开发的移动应用程序中,我想显示我从设备的本地存储中挑选的视频的缩略图。 Can anyone share a sample code that does this in Delphi.
任何人都可以分享在 Delphi 中执行此操作的示例代码。
Edited as per @Dave Nottage suggestion.根据@Dave Nottage 的建议进行了编辑。 Now all i need is a way to acquire the absolute path of the picked video file.
现在我需要的是一种获取所选视频文件的绝对路径的方法。
procedure TForm1.OpenFileSelector(Sender: TObject; const APermissions: TArray<string>;
const AGrantResults: TArray<TPermissionStatus>);
var
Intent: JIntent;
begin
FMessageSubscriptionID := TMessageManager.DefaultManager.SubscribeToMessage(TMessageResultNotification,
HandleActivityMessage);
Intent := TJIntent.JavaClass.init(TJIntent.JavaClass.ACTION_PICK);
Intent.setType(StringToJString('video/*'));
Intent.setAction(TjIntent.JavaClass.ACTION_GET_CONTENT);
Intent.putExtra(TJIntent.JavaClass.EXTRA_ALLOW_MULTIPLE, true);
Tandroidhelper.Activity.startActivityForResult(Intent,0);
{$ENDIF}
end;
//-----------------------------
procedure TForm1.HandleActivityMessage(const Sender: TObject; const aMessage: TMessage);
// when message is received
begin
if aMessage is TMessageResultNotification then
HandleIntentAction(TMessageReceivedNotification(aMessage).Value);
end;
//-------------------------------------------
function TForm1.HandleIntentAction(const Data: JIntent): Boolean;
{code to get the details of the file selected from gallery}
//============
function LoadBitmapFromJBitmap(const ABitmap: TBitmap; const AJBitmap: JBitmap): Boolean;
var
LSurface: TBitmapSurface;
begin
LSurface := TBitmapSurface.Create;
try
Result := JBitmapToSurface(AJBitmap, LSurface);
if Result then
ABitmap.Assign(LSurface);
finally
LSurface.Free;
end;
end;
//---------------
procedure AssignVideoThumbnails(aPath: string);
var
LBitmap: JBitmap;
LFileName: string;
begin
// LFileName := TPath.Combine(TPath.GetDocumentsPath, 'SampleVideo.mp4'); {using the paramter aPath instead}
LBitmap := TJThumbnailUtils.JavaClass.createVideoThumbnail(StringToJString(aPath), TJImages_Thumbnails.JavaClass.MICRO_KIND); // 96 x 96
if Assigned(LBitmap) then
LoadBitmapFromJBitmap(Image1.Bitmap, LBitmap);
end;
//============
var
vURI: JString;
vFilePath: string;
begin
if Assigned(Data) then begin
vURI := Data.getData.getPath; //getPath returns URI path
vFilePath := ???? // I NEED THE ABSOLUTE PATH of the selected file here
AssignVideoThumbnails(vFilePath);
end;
end;
Here's an example:这是一个例子:
uses
System.IOUtils,
Androidapi.JNI.Media, Androidapi.Helpers, Androidapi.JNI.GraphicsContentViewText, Androidapi.JNI.Provider,
FMX.Surfaces, FMX.Helpers.Android;
function LoadBitmapFromJBitmap(const ABitmap: TBitmap; const AJBitmap: JBitmap): Boolean;
var
LSurface: TBitmapSurface;
begin
LSurface := TBitmapSurface.Create;
try
Result := JBitmapToSurface(AJBitmap, LSurface);
if Result then
ABitmap.Assign(LSurface);
finally
LSurface.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
LBitmap: JBitmap;
LFileName: string;
begin
LFileName := TPath.Combine(TPath.GetDocumentsPath, 'SampleVideo.mp4');
LBitmap := TJThumbnailUtils.JavaClass.createVideoThumbnail(StringToJString(LFileName), TJImages_Thumbnails.JavaClass.MICRO_KIND); // 96 x 96
LoadBitmapFromJBitmap(Image1.Bitmap, LBitmap);
end;
I deployed a sample video using Deployment Manager to a remote path of ./assets/internal
, which in code equates to TPath.GetDocumentsPath
.我使用部署管理器将示例视频部署到
./assets/internal
的远程路径,在代码中等同于TPath.GetDocumentsPath
。
LoadBitmapFromJBitmap
does pretty much what it says: takes a JBitmap
and puts it into a TBitmap
:-) LoadBitmapFromJBitmap
的作用与它所说的差不多:接受一个JBitmap
并将其放入一个TBitmap
:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.