{"record":{"id":"32b45c747d0f2d89","repo":"MuntashirAkon/AppManager","slug":"failed-to-create-thumbnail","errorCode":null,"errorMessage":"Failed to create thumbnail","messagePattern":"Failed to create thumbnail","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/compat/ThumbnailUtilsCompat.java","lineNumber":54,"sourceCode":"     * @param uri     The audio Uri.\n     * @param size    The desired thumbnail size.\n     * @throws IOException If any trouble was encountered while generating or loading the thumbnail, or if\n     *                     {@link CancellationSignal#cancel()} was invoked.\n     */\n    public static @NonNull Bitmap createAudioThumbnail(@NonNull Context context, @NonNull Uri uri, @NonNull Size size,\n                                                       @Nullable CancellationSignal signal) throws IOException {\n        // Checkpoint before going deeper\n        if (signal != null) signal.throwIfCanceled();\n\n        try (MediaMetadataRetriever retriever = new MediaMetadataRetriever()) {\n            retriever.setDataSource(context, uri);\n            final byte[] raw = retriever.getEmbeddedPicture();\n            if (raw != null) {\n                Bitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length);\n                return getThumbnail(bitmap, size, true);\n            }\n        } catch (RuntimeException e) {\n            throw new IOException(\"Failed to create thumbnail\", e);\n        }\n        throw new IOException(\"No album art found\");\n    }\n\n    /**\n     * Create a thumbnail for given video file.\n     * <p>\n     * This method should only be used for files that you have direct access to;\n     * if you'd like to work with media hosted outside your app, consider using\n     * {@link ContentResolver#loadThumbnail(Uri, Size, CancellationSignal)}\n     * which enables remote providers to efficiently cache and invalidate\n     * thumbnails.\n     *\n     * @param context The Context to use when resolving the video Uri.\n     * @param uri     The video file.\n     * @param size    The desired thumbnail size.\n     * @throws IOException If any trouble was encountered while generating or\n     *                     loading the thumbnail, or if","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/compat/ThumbnailUtilsCompat.java#L36-L72","documentation":"Wrapped RuntimeException from ThumbnailUtilsCompat.createAudioThumbnail: while extracting embedded album art via MediaMetadataRetriever and decoding it with BitmapFactory, any runtime failure (decoder crash, retriever error) is rethrown as an IOException with this message.","triggerScenarios":"MediaMetadataRetriever.setDataSource succeeds but getEmbeddedPicture() or BitmapFactory.decodeByteArray throws — corrupt audio file, OOM while decoding a huge embedded image, or a native retriever error on a malformed file.","commonSituations":"Scanning a media library containing corrupt or exotic-format audio files; low-memory devices where a multi-megabyte embedded cover art fails to decode; files with broken ID3/Vorbis picture tags.","solutions":["Catch the IOException and fall back to a placeholder/default artwork","Pre-scale or stream-decode with BitmapFactory.Options inSampleSize to avoid OOM (custom retriever code)","Validate the file with MediaMetadataRetriever before thumbnailing, skipping corrupt files","Ensure the file is fully readable (not truncated mid-copy) before calling"],"exampleFix":"// before\nBitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length);\nreturn getThumbnail(bitmap, size, true);\n// after\nBitmapFactory.Options opts = new BitmapFactory.Options();\nopts.inSampleSize = 2;\nBitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length, opts);\nif (bitmap == null) throw new IOException(\"No album art found\");\nreturn getThumbnail(bitmap, size, true);","handlingStrategy":"try-catch","validationCode":"// pre-check embedded art presence\nMediaMetadataRetriever mmr = new MediaMetadataRetriever();\nmmr.setDataSource(path);\nbyte[] art = mmr.getEmbeddedPicture();\nmmr.release();\nif (art == null) return null; // no artwork: skip thumbnailing","typeGuard":null,"tryCatchPattern":"try {\n    return ThumbnailUtilsCompat.createAudioThumbnail(file, size);\n} catch (IOException e) {\n    if (e.getCause() instanceof OutOfMemoryError) System.gc();\n    return placeholderArt;\n}","preventionTips":["Pre-check getEmbeddedPicture()","Use inSampleSize for large art","Skip known-corrupt files","Run thumbnailing off the main thread"],"tags":["android","thumbnail","audio","bitmap"],"backgroundTag":"bitmap-decode-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}