Skip to content

Fix : AsyncImage cannot decode video thumbnail from URI#2062

Open
jbsession wants to merge 3 commits intodevfrom
fix/movie-preview
Open

Fix : AsyncImage cannot decode video thumbnail from URI#2062
jbsession wants to merge 3 commits intodevfrom
fix/movie-preview

Conversation

@jbsession
Copy link
Collaborator

@jbsession jbsession commented Mar 19, 2026

Our URI does not have a file extension so we need to check for the MIME type then explicitly set the decoder for the request.

Also fixed play button image.

Screenshot 2026-03-19 at 2 14 48 PM

@jbsession jbsession self-assigned this Mar 19, 2026
@jbsession jbsession requested review from SessionHero01 and ThomasSession and removed request for SessionHero01 March 19, 2026 06:09
@jbsession jbsession changed the title Fix : AsyncImage cannot decode vide URI Fix : AsyncImage cannot decode video thumbnail from URI Mar 19, 2026
decoderFactory(VideoFrameDecoder.Factory())
}
}
.build()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will re-execute on every re-composition.
You should probably optimise with something like:

val videoDecoderFactory = remember { VideoFrameDecoder.Factory() }

    val folderThumbnailRequest = remember(context, thumbnailUri) {
        val mimeType = thumbnailUri?.let { MediaUtil.getMimeType(context, it) }

        ImageRequest.Builder(context)
            .data(thumbnailUri)
            .apply {
                if (MediaUtil.isVideoType(mimeType)) {
                    decoderFactory(videoDecoderFactory)
                }
            }
            .build()
    }

if (MediaUtil.isVideoType(media.mimeType)) {
decoderFactory(VideoFrameDecoder.Factory())
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You probably want to optimise here as well:

val videoDecoderFactory = remember { VideoFrameDecoder.Factory() }

val mediaRequest = remember(context, media.uri, media.mimeType) {
    ImageRequest.Builder(context)
        .data(media.uri)
        .apply {
            if (MediaUtil.isVideoType(media.mimeType)) {
                decoderFactory(videoDecoderFactory)
            }
        }
        .build()
}

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.

3 participants