0

我正在使用 Jetpack Compose 实现一个简单的画廊屏幕,它在屏幕上显示所有视频和图像缩略图

我已成功显示来自文件路径的图像。但是,我在显示视频缩略图时遇到了麻烦。我怎么能用线圈做到这一点?

这是我显示图像缩略图的代码:

@Composable
fun ImageLoaderFromLocal(
    url: String,
    placeHolderResId: Int,
    modifier: Modifier,
    transformation: Transformation
) {
    val painter = rememberImagePainter(data = File(url),
        builder = {
            placeholder(placeHolderResId)
            crossfade(true)
            transformations(transformation)
        })

    Image(
        painter = painter,
        contentDescription = null,
        modifier = modifier,
        contentScale = ContentScale.Inside
    )
}
4

1 回答 1

2

根据 Coil文档,您需要添加以下依赖项:

implementation("io.coil-kt:coil-video:$coil_version")

并在构建器中指定 fetcher:

val context = LocalContext.current
val painter = rememberImagePainter(
    data = url,
    builder = {
        fetcher(VideoFrameUriFetcher(context))
        // optionally set frame location
        videoFrameMillis(1000)

        placeholder(placeHolderResId)
        crossfade(true)
        transformations(transformation)
    }
)
于 2021-09-27T08:31:23.210 回答