Mur*_*kov 2 android android-jetpack-compose coil
我正在使用 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
)
}
Run Code Online (Sandbox Code Playgroud)
根据 Coil文档,您需要添加以下依赖项:
implementation("io.coil-kt:coil-video:$coil_version")
Run Code Online (Sandbox Code Playgroud)
并在构建器中指定 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)
}
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4074 次 |
| 最近记录: |