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

Taking care of the possible null value that can be returned by mediaExtractor.getTrackFormat #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

develric
Copy link

Hi there 👋 .
We have this issue here where we get the following:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.m4m.domain.MediaFormat.getMimeType()' on a null object reference
        at org.m4m.domain.MediaSource.getMediaFormatByType(MediaSource.java:166)
        at org.m4m.MediaFile.getVideoFormat(MediaFile.java:112)
        at org.m4m.MediaFileInfo.prepareMediaFile(MediaFileInfo.java:135)
        at org.m4m.MediaFileInfo.setUri(MediaFileInfo.java:88)

Looking into it, we are getting that Null Pointer Exception in some cases/conditions:

  • specific videos,
  • specific devices like Pixel 4a or some Samsung devices and also Pixel 3 Emulator;
  • various API levels but it seems it can depend from the device custom flavour of Android; for example matching other conditions, no problems in a OnePlus 7T.

If I'm not wrong, the issue seems related to the fact that the mediaExtractor.getTrackFormat can return a null value:

@Override
    public MediaFormat getTrackFormat(int index) {
        if (mediaExtractor.getTrackFormat(index).getString(android.media.MediaFormat.KEY_MIME).contains("video")) {
            return new VideoFormatAndroid(mediaExtractor.getTrackFormat(index));
        } else if (mediaExtractor.getTrackFormat(index).getString(android.media.MediaFormat.KEY_MIME).contains("audio")) {
            return new AudioFormatAndroid(mediaExtractor.getTrackFormat(index));
        }
        return null;
    }

and in one case I could verify we had 3 tracks rescued by mediaExtractor.getTrackFormat with values

  • mediaExtractor.getTrackFormat(0).getString(android.media.MediaFormat.KEY_MIME) -> application/meta
  • mediaExtractor.getTrackFormat(1).getString(android.media.MediaFormat.KEY_MIME) -> audio/mp4a-latm
  • mediaExtractor.getTrackFormat(2).getString(android.media.MediaFormat.KEY_MIME) -> video/avc

the first raw is a possible scenario when we can get the crash returning a null value.

Linking to the lib code of this PR I could verify that all worked ok for me. Also checked the samples in the lib and AFAIU seems working ok.

I see the lib is already checking that possible null return value in all the other places in MediaSource.java so the modification should just add that check all over the places where it's used.
I was wondering if you could review this PR and confirm if it can be fine to merge (I'm not familiar with your code base so happy to get your feedbacks).

Thanks for your attention and time 🙇‍♂️.

Copy link
Contributor

@daniloercoli daniloercoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

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

Successfully merging this pull request may close these issues.

2 participants