0

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

Qamar
  • 4,959
  • 1
  • 30
  • 49
  • @pskink this will work in case on external and i have docId usb1002:/GOPR0462.MP4 and docRootId = "usb1002" but getThumbnail needs long id. check it's documentation – Qamar Mar 14 '17 at 11:05
  • ok then try `MediaMetadataRetriever` it has `setDataSource(Context context, Uri uri)` method so it could work – pskink Mar 14 '17 at 12:03
  • @pskink can't set uri. It says java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA – Qamar Mar 14 '17 at 12:23
  • so as @CommonsWare said, you have `"to copy the contents of that file"` somewhere – pskink Mar 14 '17 at 12:25
  • @pskink Which is best for USB video explorer. http://stackoverflow.com/a/31732525/5710872 or mjdev:libaums. – Qamar Mar 14 '17 at 12:39
  • i never heard about `mjdev:libaums` – pskink Mar 14 '17 at 12:41

1 Answers1

1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • You are right. I think I should use to `InputStream is = new UsbFileInputStream(usbFile);` thanks – Qamar Mar 14 '17 at 11:52
  • This means I will face problem when I use usbFile to play video in exo player and Android VideoView without copying content. What do you suggest? – Qamar Mar 14 '17 at 11:56
  • @Qamar: You can try passing the `Uri` from the `StorageProvider` to the third-party app. Or, you would have to use the HTTP library integration, bearing in mind that this has security ramifications. – CommonsWare Mar 14 '17 at 12:16
  • Content is located in connected OTG USB with Android device. Why integrate HTTP library plz explain for my knowledge. By the way all videos playing with native USB explorer. FYI. I am developing only USB media explorer with image viewer and video player built-in. – Qamar Mar 14 '17 at 12:29
  • 1
    @Qamar: "all videos playing with native USB explorer" -- the system is making that content available via a `ContentProvider`, and the system has better access to removable storage than you do. "Why integrate HTTP library" -- you can either copy the video, try the library's `StorageProvider` as a `ContentProvider`, or you can serve the video to the player via an embedded Web server (again, with security ramifications). You do not have many options that will both work with your chosen library and with a media player. – CommonsWare Mar 14 '17 at 12:39
  • #CommonsWare Then which is correct choice to load USB files that has little more options than sucker `mjdev:libaums`. It's not too late. plz – Qamar Mar 14 '17 at 12:52
  • @Qamar: That library is probably about as good as you are going to get. Personally, I would not dream of writing the app that you are trying to write, as Android specifically makes that sort of thing difficult. I would work with the author of that library to get an easy way to get a `Uri` to a `UsbFile` from the `StorageProvider`, if there is no equivalent to `FileProvider`'s `getUriForFile()` already in there. Then, hand that `Uri` over to the media player, and hope for the best. Many media players will not work, due to limitations imposed on the streams from that provider. – CommonsWare Mar 14 '17 at 13:20
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/138090/discussion-between-qamar-and-commonsware). – Qamar Mar 15 '17 at 10:08