Search code examples
androidkotlinandroid-jetpack-composecoil

Error Loading a thumbnail for a video using Coil jetpack compose kotlin


I was trying to generate a thumbnail for a video. The video is from a link on the Internet. Here's the code I'm using to generate the thumbnail:

import coil.ImageLoader
import coil3.video.VideoFrameDecoder

val videoEnabledLoader =
    ImageLoader.Builder(context).components {
        add(VideoFrameDecoder.Factory())
    }.build()

But it gives me this error:

None of the following functions can be called with the arguments supplied.

It specifically points on the add function

Here's the dependencies I am using:

implementation("io.coil-kt:coil-compose:2.5.0")
implementation("io.coil-kt.coil3:coil-video:3.0.3")

Solution

  • You are mixing incompatible Coil versions.

    For the ImageLoader.Builder you use Coil 2.5.0, for the VideoFrameDecoder.Factory you use 3.0.3. The reason for the compile error is that the add function requires a

    coil.decode.Decoder.Factory
    

    but you provide a

    coil3.decode.Decoder.Factory
    

    That doesn't work.

    You need to fix your gradle dependencies to use the same version for all Coil artifacts. Either downgrade to 2.5.0:

    implementation("io.coil-kt:coil-compose:2.5.0")
    implementation("io.coil-kt:coil-video:2.5.0")
    

    and use

    import coil.ImageLoader
    import coil.decode.VideoFrameDecoder
    

    or upgrade to 3.0.3:

    implementation("io.coil-kt.coil3:coil-compose:3.0.3")
    implementation("io.coil-kt.coil3:coil-video:3.0.3")
    

    and use

    import coil3.ImageLoader
    import coil3.video.VideoFrameDecoder
    

    You should probably use a variable for the Coil version and use it in the gradle dependency to mitigate the risk of version mismatches in the future, or - better yet - migrate to version catalogs.