0

I'm trying to load video frame from video, provided in previewUrl = "https://<..>.mp4", but nothings happens. I've tried removing/changing fetcher, modifier, frameMillis, but still nothing. My previewUrl is valid and I can open it on my PC, it's just several seconds video. Thank you for any help.

Image(
    painter = rememberImagePainter(
        data = previewURL,
        builder = {
            fetcher(VideoFrameUriFetcher(context))
            videoFrameMillis(1000)
        }
    ),
    contentDescription = "video frame",
    modifier = Modifier.size(128.dp)
)
Captain Jacky
  • 888
  • 1
  • 12
  • 26
  • 2
    According to the Coil documentation https://coil-kt.github.io/coil/videos/ . `VideoFrameUriFetcher` only works for files and local Uris. But you are trying to load Preview from Web and for that you must use `VideoFrameDecoder`. – Vaibhav Goyal Nov 04 '21 at 06:25
  • It did load, I misconfigured the size. You can post this as an answer, I'll accept it. Thanks. – Captain Jacky Nov 04 '21 at 06:41

1 Answers1

1

This is the code I'm using to render a preview Image for a video url using coil-video:

@Composable
fun VideoThumbnail(
    modifier: Modifier = Modifier,
    url: String = "",
) {
    AndroidView(
        modifier = modifier,
        factory = { ImageView(it).loadVideoUrl(url) },
        update = { it.loadVideoUrl(url) }
    )
}

fun ImageView.loadVideoUrl(url: String) = this.apply {
    load(url) {
        decoderFactory { result, options, _ ->
            VideoFrameDecoder(
                result.source,
                options
            )
        }
    }
    scaleType = ImageView.ScaleType.CENTER_CROP
}

I've tried with other solutions, but this is the only one that worked for me.. Remember set a proper scaleType.

aldajo92
  • 181
  • 1
  • 5