簡體   English   中英

如何從 Delphi 10.3 平台中的 android 設備中檢索視頻的縮略圖?

[英]How can i retrieve the thumbnails of a video from an android device in a Delphi 10.3 platform?

在 Delphi 10.3 下開發的移動應用程序中,我想顯示我從設備的本地存儲中挑選的視頻的縮略圖。 任何人都可以分享在 Delphi 中執行此操作的示例代碼。

根據@Dave Nottage 的建議進行了編輯。 現在我需要的是一種獲取所選視頻文件的絕對路徑的方法。

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;

這是一個例子:

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;

我使用部署管理器將示例視頻部署到./assets/internal的遠程路徑,在代碼中等同於TPath.GetDocumentsPath

LoadBitmapFromJBitmap的作用與它所說的差不多:接受一個JBitmap並將其放入一個TBitmap :-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM