1

The last line in the below code where I set the FileDescriptor as a data source of the MediaMetadataRetriever throws IllegalArgumentException (MediaMetadataRetrieverJNI: invalid file descriptor.)

ContentResolver resolver = getActivity().getBaseContext().getContentResolver();
    final ParcelFileDescriptor parcelFileDescriptor;
    try {
        Uri uri = Uri.fromFile(new File(videoPath));
        parcelFileDescriptor = resolver.openFileDescriptor(uri, "r");
    } catch (FileNotFoundException e) {
        Log.w("Could not open '" + videoPath + "'", e);
        Toast.makeText(getActivity(), "File not found.", Toast.LENGTH_LONG).show();
        return;
    }
    FileDescriptor fileDescriptor = null;
    if (parcelFileDescriptor != null) {
        fileDescriptor = parcelFileDescriptor.getFileDescriptor();
        if(fileDescriptor == null)
            Log.i(TAG, "fileDescriptor is null.");
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
    mediaMetadataRetriever.setDataSource(mInputFileDescriptor);

Any idea what causes the FileDescriptor to be invalid? Thanks.

  • Perhaps you do not have access to the file. Or, perhaps `videoPath` is not a valid path. – CommonsWare Jun 15 '16 at 23:10
  • By "having access" you mean having read permission? The path is a valid one, it would throw FileNotFoundException if it's not, right? – Mohamad Hussein Jun 16 '16 at 04:07
  • "By "having access" you mean having read permission?" -- yes. "The path is a valid one, it would throw FileNotFoundException if it's not, right?" -- ideally, yes, but not necessarily. – CommonsWare Jun 16 '16 at 11:05
  • @CommonsWare well, I do have WRITE_EXTERNAL_STORAGE permission and the path is valid and pointing to /storage/emulated/0/TH1466425121490.mp4, for example. What else to check for? – Mohamad Hussein Jun 20 '16 at 12:49
  • "I do have WRITE_EXTERNAL_STORAGE permission" -- are you handling runtime permissions? http://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it – CommonsWare Jun 20 '16 at 12:53
  • @CommonsWare Well, I still haven't done any runtime permissions handling across the app, and I'm testing on a physical device with Lollipop on it, not Marshmallow. – Mohamad Hussein Jun 21 '16 at 13:59

0 Answers0