coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.83k stars 664 forks source link

VideoFrameDecoder fails on local file uri #2625

Closed edenman closed 2 weeks ago

edenman commented 2 weeks ago

Describe the bug Video doesn't show a preview frame. Images load fine using the same @Composable

2024-11-01 16:20:30.274 14767-14767 RealImageLoader         com.my.package                  I  🚨 Failed - file:///data/user/0/com.my.package/cache/path/to/video.mp4 - java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
2024-11-01 16:20:30.323 14767-14767 RealImageLoader         com.my.package                  I  💾 Successful (DISK) - file:///data/user/0/com.my.package/cache/path/to/image.jpg

To Reproduce

    val imageRequest = ImageRequest.Builder(LocalContext.current)
        .data(uri)
        .crossfade(true)
        .build()
    AsyncImage(
        model = imageRequest,
        placeholder = ColorPainter(HorizonTheme.colors.secondaryText),
        contentDescription = null, // TODO
        modifier = modifier,
    )

My ImageLoader is pretty simple

ImageLoaderFactory {
        ImageLoader.Builder(context)
            .components {
                add(VideoFrameDecoder.Factory())
                add(ImageDecoderDecoder.Factory())
            }
            .okHttpClient { sharedOkHttpClient }
            .build()
    }

Version Coil 2.6.0 testing on a Pixel 4

edenman commented 2 weeks ago

The file in question, but this happens for all video files afaict https://github.com/user-attachments/assets/87fc98f3-5340-4406-b9ae-4a659fae3a78

edenman commented 2 weeks ago
java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
    at android.media.MediaMetadataRetriever._setDataSource(Native Method)
    at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:281)
    at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:247)
    at coil.decode.VideoFrameDecoder.setDataSource(VideoFrameDecoder.kt:204)
    at coil.decode.VideoFrameDecoder.decode(VideoFrameDecoder.kt:42)
    at coil.intercept.EngineInterceptor.decode(EngineInterceptor.kt:203)
    at coil.intercept.EngineInterceptor.access$decode(EngineInterceptor.kt:42)
    at coil.intercept.EngineInterceptor$execute$executeResult$1.invokeSuspend(EngineInterceptor.kt:131)
    at coil.intercept.EngineInterceptor$execute$executeResult$1.invoke(Unknown Source:8)
    at coil.intercept.EngineInterceptor$execute$executeResult$1.invoke(Unknown Source:4)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:42)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:164)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
    at coil.intercept.EngineInterceptor.execute(EngineInterceptor.kt:130)
    at coil.intercept.EngineInterceptor.access$execute(EngineInterceptor.kt:42)
    at coil.intercept.EngineInterceptor$intercept$2.invokeSuspend(EngineInterceptor.kt:77)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
    at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:113)
    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:589)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:823)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:707)
colinrtwhite commented 2 weeks ago

Just to confirm, this is a file:// uri/path? I tried loading the video with the latest 3.0.0-rc02 version and it worked OK:

It's possible this is a hardware or API-specific bug.

edenman commented 2 weeks ago

Yeah file:// path. I’ll try another device on Monday

edenman commented 2 weeks ago

No luck on other devices. Tried updating my main test device to android 14, no luck. Updated to Coil 3.0 rc2. Same issue. Gotta be something about the file path, will keep digging.

edenman commented 2 weeks ago

There was a colon in the folder name, if I remove that everything works great 🤣 😭 .

colinrtwhite commented 2 weeks ago

Ah nice find. I think Coil 3 should better support path names with different characters since we use a custom Uri class instead of android.net.Uri.