https://kotlinlang.org logo
#compose
Title
# compose
f

Felix Schütz

09/02/2021, 8:40 AM
When using Coil to load videos from URIs generated with
ContentResolver
, I need to explicitly pass the fetcher to the request builder, otherwise Coil cannot process the video (since the URI does not contain the file type). E.g.:
Copy code
Image(
    painter = rememberImagePainter(
        data = contentUri,
        builder = {
            fetcher(VideoFrameUriFetcher(LocalContext.current))
        },
    ),
    contentDescription = null,
)
Creating the
VideoFrameUriFetcher
instance for every video seems kind of inefficient. Is there a better Compose way?
a

Alex

09/02/2021, 9:04 AM
Why not hoist the video frame fetcher?
1
f

Felix Schütz

09/02/2021, 9:46 AM
Yeah, probably makes sense. Thanks.
a

Alex

09/03/2021, 6:43 AM
The frame fetcher could live inside your viewmodel too so it won't be recreated on every recomposition, although I am not sure if
builder
already does some caching for you
109 Views