如何从UsbStorageProvider文档uri获取视频缩略图

时间:2017-03-14 10:23:31

标签: java android android-contentprovider usb-otg

问题的根源是来自mjdev:libaums和UsbStorageProvider的UsbFile

我尝试从uri.getPath()中提取视频帧 - > /document/usb1002:/GOPR04252.MP4

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

来自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;
        }
....
}

但它返回null。 为什么以及如何解决它?有没有其他方法可以解决这个问题

UsbStorageProvider

中检查已注释的getUsbPath方法调用
//row.add(Document.COLUMN_PATH, getUsbPath(file));

如何实现返回该文件路径的getUsbPath(UsbFile)方法?

推定,如果我们将UsbFile转换为FiledocumentUri转换为File

,我们可以解决问题

在{OTC

1 个答案:

答案 0 :(得分:1)

  

但它返回null。为什么

您正在传递一个随机字符串,一个是通过调用<{1}}上的getPath()获得的, Uri方案。这类似于在指向此网页的file上调用getPath(),然后想知道为什么您的硬盘驱动器没有位于Uri的文件。

  

如何实现返回该文件路径的getUsbPath(UsbFile)方法?

按照the documentation中的说明将该文件的内容复制到您控制的文件(例如/questions/42783353/custom-provider-uri-to-path-or-usbfile-to-file-path)。

或者,找一些仅适用于getCacheDir()的API,并将其设为InputStream

相关问题