Android Coil 3拦截器Interceptor计算单次请求耗时,Kotlin

Android Coil 3拦截器Interceptor计算单次请求耗时,Kotlin

Kotlin 复制代码
import android.content.Context
import android.util.Log
import coil3.intercept.Interceptor
import coil3.request.ImageResult

class MyInterceptor : Interceptor {
    companion object {
        const val TAG = "fly/MyInterceptor"
    }

    private var mCtx: Context? = null

    constructor(ctx: Context) {
        mCtx = ctx
    }

    override suspend fun intercept(chain: Interceptor.Chain): ImageResult {

        val t = System.currentTimeMillis()
        val result = chain.proceed()
        Log.d(TAG, "耗时:${System.currentTimeMillis() - t} ms, ${chain.request.data}")

        return result
    }
}
Kotlin 复制代码
        mImageLoader = ImageLoader.Builder(ctx)

            ...
            .components {
                ...

                add(MyInterceptor(ctx))
                
            }.build()

Android Coil3视频封面抽取封面帧存Disk缓存,Kotlin(2)-CSDN博客文章浏览阅读444次,点赞9次,收藏14次。本文介绍了基于Coil3的Android视频封面抽取优化方案,重点改进了磁盘缓存性能。通过将封面帧从PNG无损格式改为JPEG有损压缩(质量80),使缓存文件大小缩减至原先的1/10,显著提升了读写速度。核心实现包括:1)使用FFmpegMediaMetadataRetriever快速抽取视频首帧;2)自定义Bitmap压缩参数(Bitmap.CompressFormat.JPEG);3)采用缓冲流(BufferedOutputStream)处理磁盘缓存写入。该方案在保持图像质量的同时优化了I/O性能,适用https://blog.csdn.net/zhangphil/article/details/150494282

相关推荐
阿pin11 小时前
Android随笔-kotlin withContext
android·kotlin·withcontext
树码小子12 小时前
开启 IDEA 中的断言功能
android·java·intellij-idea
Kslient12 小时前
HeaderBehavior
android
Android-Flutter13 小时前
android 动画详解
android·kotlin
小孔龙18 小时前
GraphicBuffer 跨进程共享
android
行业研究员18 小时前
Android内置GPS与腾讯地图定位技术对比分析
android·android定位·腾讯地图定位
Android-Flutter19 小时前
android WMS 详解(二)
android·kotlin
游戏开发爱好者820 小时前
App Store 上传 IPA 自动化,.p8 密钥认证与 CI/CD 接入实战
android·运维·ci/cd·小程序·uni-app·自动化·iphone
游戏开发爱好者821 小时前
iOS 推送怎么配置,APNs 推送证书、设备库与群发
android·ios·小程序·https·uni-app·iphone·webview
阿pin21 小时前
Android随笔-kotlin 高阶函数
android·kotlin·高阶函数