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

AndroidRuntime: java.util.concurrent.TimeoutException: android.media.MediaMetadataRetriever.finalize() timed out after 10 seconds #165

Open
ProFive opened this issue Jul 3, 2024 · 0 comments

Comments

@ProFive
Copy link

ProFive commented Jul 3, 2024

It's happening on some devices when creating a thumbnail from a video mp4 and mov ( xiaomi 12T and honor 50)

public Bitmap createVideoThumbnail(final String video, final HashMap<String, String> headers, int targetH,
int targetW, int timeMs) {
Bitmap bitmap = null;
try (MediaMetadataRetriever retriever = new MediaMetadataRetriever()) {
try {
if (video.startsWith("/")) {
setDataSource(video, retriever);
} else if (video.startsWith("file://")) {
setDataSource(video.substring(7), retriever);
} else {
retriever.setDataSource(video, (headers != null) ? headers : new HashMap<String, String>());
}

        if (targetH != 0 || targetW != 0) {
            if (android.os.Build.VERSION.SDK_INT >= 27 && targetH != 0 && targetW != 0) {
                // API Level 27
                bitmap = retriever.getScaledFrameAtTime(timeMs * 1000, MediaMetadataRetriever.OPTION_CLOSEST,
                        targetW, targetH);
            } else {
                bitmap = retriever.getFrameAtTime(timeMs * 1000, MediaMetadataRetriever.OPTION_CLOSEST);
                if (bitmap != null) {
                    int width = bitmap.getWidth();
                    int height = bitmap.getHeight();
                    if (targetW == 0) {
                        targetW = Math.round(((float) targetH / height) * width);
                    }
                    if (targetH == 0) {
                        targetH = Math.round(((float) targetW / width) * height);
                    }
                    Log.d(TAG, String.format("original w:%d, h:%d => %d, %d", width, height, targetW, targetH));
                    bitmap = Bitmap.createScaledBitmap(bitmap, targetW, targetH, true);
                }
            }
        } else {
            bitmap = retriever.getFrameAtTime(timeMs * 1000, MediaMetadataRetriever.OPTION_CLOSEST);
        }
    } catch (IllegalArgumentException ex) {
        ex.printStackTrace();
    } catch (RuntimeException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        try {
            retriever.release();
        } catch (RuntimeException | IOException ex) {
            ex.printStackTrace();
        }
    }
} catch (IOException e) {
    e.printStackTrace();
}

return bitmap;
}

ERROR MESSAGE:

07-03 11:24:16.780 27078 27093 E AndroidRuntime: Process: com.fivegencare.com.motorola.nursery, PID: 27078 07-03 11:24:16.780 27078 27093 E AndroidRuntime: java.util.concurrent.TimeoutException: android.media.MediaMetadataRetriever.finalize() timed out after 10 seconds 07-03 11:24:16.780 27078 27093 E AndroidRuntime: at android.media.MediaMetadataRetriever.native_finalize(Native Method) 07-03 11:24:16.780 27078 27093 E AndroidRuntime: at android.media.MediaMetadataRetriever.finalize(MediaMetadataRetriever.java:1069) 07-03 11:24:16.780 27078 27093 E AndroidRuntime: at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:291) 07-03 11:24:16.780 27078 27093 E AndroidRuntime: at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:278) 07-03 11:24:16.780 27078 27093 E AndroidRuntime: at java.lang.Daemons$Daemon.run(Daemons.java:139) 07-03 11:24:16.780 27078 27093 E AndroidRuntime: at java.lang.Thread.run(Thread.java:923) 07-03 11:24:37.204 31964 31964 I ActivityThread: smart_link is not supported!!! 07-03 11:28:42.580 2225 2225 I ActivityThread: smart_link is not supported!!! 07-03 11:33:34.152 6548 6548 I ActivityThread: smart_link is not supported!!! 07-03 11:40:56.803 9739 9739 I ActivityThread: smart_link is not supported!!! 07-03 11:42:04.672 9739 9783 E AndroidRuntime: FATAL EXCEPTION: FinalizerWatchdogDaemon 07-03 11:42:04.672 9739 9783 E AndroidRuntime: Process: com.fivegencare.com.motorola.nursery, PID: 9739 07-03 11:42:04.672 9739 9783 E AndroidRuntime: java.util.concurrent.TimeoutException: android.media.MediaMetadataRetriever.finalize() timed out after 10 seconds 07-03 11:42:04.672 9739 9783 E AndroidRuntime: at android.media.MediaMetadataRetriever.native_finalize(Native Method) 07-03 11:42:04.672 9739 9783 E AndroidRuntime: at android.media.MediaMetadataRetriever.finalize(MediaMetadataRetriever.java:1069) 07-03 11:42:04.672 9739 9783 E AndroidRuntime: at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:291) 07-03 11:42:04.672 9739 9783 E AndroidRuntime: at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:278) 07-03 11:42:04.672 9739 9783 E AndroidRuntime: at java.lang.Daemons$Daemon.run(Daemons.java:139) 07-03 11:42:04.672 9739 9783 E AndroidRuntime: at java.lang.Thread.run(Thread.java:923) 07-03 11:42:33.173 13369 13369 I ActivityThread: smart_link is not supported!!!

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

1 participant