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

相关推荐
撩得Android一次心动3 小时前
Android 四大组件桥梁 —— Intent (意图) 详解
android
用户2018792831674 小时前
MVP架构模式:餐厅点餐的有趣故事
android
用户2018792831674 小时前
MVVM 架构模式:咖啡馆的智能点餐系统
android
用户2018792831674 小时前
浅析Android MVC架构
android
AsiaLYF6 小时前
kotlin中MutableStateFlow和MutableSharedFlow的区别是什么?
android·开发语言·kotlin
2501_916008896 小时前
iOS 发布全流程详解,从开发到上架的流程与跨平台使用 开心上架 发布实战
android·macos·ios·小程序·uni-app·cocoa·iphone
4Forsee6 小时前
【Android】浅析 Android 的 IPC 跨进程通信机制
android·java
叶羽西7 小时前
如何区分Android、Android Automotive、Android Auto
android
用户2018792831677 小时前
用 “奶茶店订单系统” 讲懂 MVI 架构
android
LiuYaoheng7 小时前
【Android】布局优化:include、merge、ViewStub的使用及注意事项
android·java