Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retriever.setDataSource(source) not working on older phones #80

Open
LianVyv opened this issue Nov 10, 2024 · 10 comments
Open

retriever.setDataSource(source) not working on older phones #80

LianVyv opened this issue Nov 10, 2024 · 10 comments

Comments

@LianVyv
Copy link

LianVyv commented Nov 10, 2024

@maitrungduc1410 I have came across this issue where my one Huawei phone is not working when setting the retriever.setDataSource(source). It keeps returning a null.

I have ended up fixing it by doing the following

public static MediaMetadataRetriever getMediaMetadataRetriever(String source) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {
      if (source.startsWith("http://") || source.startsWith("https://")) {
        retriever.setDataSource(source, new HashMap<>());
      } else {
        try (FileInputStream fis = new FileInputStream(new File(source.replace("file://", "")))) {
            retriever.setDataSource(fis.getFD());
        } catch (IOException e) {
            retriever.release();
            Log.e(TAG, "Error setting data source from file descriptor", e);
            return null;
        }
      }
      return retriever;
    } catch (Exception e) {
      Log.e(TAG, "Error setting data source", e);
      try {
        retriever.release();
      } catch (Exception ee) {
        Log.e(TAG, "Error releasing retriever", ee);
      }
      return null;
    }
  }

I have tested on my other Android phones and it seems to work fine. But not sure what impact that has on other phones. I also realised if I run

 File file = new File(mSourceUri.toString());
      if (!file.exists()) {
           map.putString("File check", "file not found");       
      }

Then I always get File not found.

So I have had to add a .replace("file://", "")

Can I create a PR for this or you see any problems?

@maitrungduc1410
Copy link
Owner

what is your phone version? (API version)

@LianVyv
Copy link
Author

LianVyv commented Nov 10, 2024

I think it is Android Version 12

IMG_2214

@maitrungduc1410
Copy link
Owner

you should search for "software information" in Settings, it should show something like Android version

@LianVyv
Copy link
Author

LianVyv commented Nov 10, 2024

Android version 10(Q)

@maitrungduc1410
Copy link
Owner

hi @LianVyv in this case the catch block will run, can you check what do you have in the error? (try to get stacktrace, message,...)

Like this:

public static MediaMetadataRetriever getMediaMetadataRetriever(String source) {
  MediaMetadataRetriever retriever = new MediaMetadataRetriever();
  try {
    if (source.startsWith("http://") || source.startsWith("https://")) {
      retriever.setDataSource(source, new HashMap<>());
    } else {
      retriever.setDataSource(source);
    }
    return retriever;
  } catch (Exception e) {
    Log.e(TAG, "Error setting data source");
    Log.e(TAG, e.printStackTrace());
    Log.e(TAG, e.getMessage());
    try {
      retriever.release();
    } catch (Exception ee) {
      Log.e(TAG, "Error releasing retriever", ee);
    }
    return null;
  }
}

@LianVyv
Copy link
Author

LianVyv commented Nov 15, 2024

@maitrungduc1410 I had to travel this week. I will get back to you on this next week when I'm back.

@bilalkhan-tech
Copy link

this package crash android app when select the video more than 2 minute and 10 seconds without showing any error and some devices show storage permission denied

@maitrungduc1410
Copy link
Owner

hi @bilalkhan-tech can you please check on Android studio -> logcat, and see what's the error printed at the time it's crashed?

@bilalkhan-tech
Copy link

bilalkhan-tech commented Dec 1, 2024 via email

@maitrungduc1410
Copy link
Owner

@bilalkhan-tech no, not console, it's LogCat from Android studio, if it's crashed, there must be some crash log there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants