Search code examples
javaandroidandroid-contentproviderusb-otg

How to get video thumbnail from UsbStorageProvider document uri


The origin of problem is UsbFile from mjdev:libaums and UsbStorageProvider.

I try to extract video frame from uri.getPath() -> /document/usb1002:/GOPR04252.MP4

like ImageUtils.getVideoThumbnail(documentUri.getPath(), size.x, size.y);

method from ImageUtils

public static Bitmap getVideoThumbnail(String path, int mMaxWidth, int mMaxHeight){
        Bitmap.Config mDecodeConfig = Bitmap.Config.RGB_565;
        ImageView.ScaleType mScaleType = ImageView.ScaleType.CENTER_CROP;

        File bitmapFile = new File(path);
        Bitmap bitmap = null;

        if (!bitmapFile.exists() || !bitmapFile.isFile()) {
            return bitmap;
        }
....
}

But it return null. Why and how to fix it?? Is there any other way to solve this problem

OR

Check commented getUsbPath method call in UsbStorageProvider

//row.add(Document.COLUMN_PATH, getUsbPath(file));

How to implement getUsbPath(UsbFile) method that return path to that file?


Presumption, We can solve situation if we convert UsbFile to File or documentUri to File

In sample words implimenting video thumbnail in AnExplorer for USB OTG


Solution

  • But it return null. Why

    You are passing in a random string, one obtained by calling getPath() on a Uri that does not have the file scheme. That is akin to calling getPath() on a Uri pointing to this Web page, then wondering why your hard drive does not have a file located at /questions/42783353/custom-provider-uri-to-path-or-usbfile-to-file-path.

    How to implement getUsbPath(UsbFile) method that return path to that file?

    Follow the instructions in the documentation to copy the contents of that file to one that you control (e.g., getCacheDir()).

    Or, find some API that works with just an InputStream, and hand it a UsbFileInputStream.