coil-kt / coil

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

[coil-video] Failed to load video on imageView #454

Closed mamadou94Diop closed 4 years ago

mamadou94Diop commented 4 years ago

Describe the bug I have a recycler view with 3 elements : an image , a gif and a video. But the video does not work and display first the placeholder and after the error drawables.

Expected behavior The item of my recycler view should display video as same as image and gif which worked well. To Reproduce How can we reproduce this? I injected the image loader as a dependency through Dagger.

@Singleton
@Provides
fun providesImageLoader(context: Context) :ImageLoader {
    return ImageLoader.Builder(context)
        .availableMemoryPercentage(0.5)
        .crossfade(true)
        .crossfade(2000)
        .placeholder(R.drawable.placeholder)
        .error(R.drawable.error)
        .componentRegistry {
            add(VideoFrameFileFetcher(context))
            add(VideoFrameUriFetcher(context))
            if (Build.VERSION.SDK_INT >= 28) {
                add(ImageDecoderDecoder())
            } else {
                add(GifDecoder())
            }
        }
        .build()
}

I used my own ImageView extension.

fun ImageView.load(uri: String, imageLoader: ImageLoader){
    val request = LoadRequest.Builder(context)
        .data(uri)
        .target(this)
        .scale(Scale.FIT)
        .build()
imageLoader.execute(request)`

The url of the video

Logs/Screenshots Screenshot

Capture d’écran 2020-07-07 à 18 42 12

Logs

2020-07-07 18:13:51.683 16572-16572/? I/.coilexperimen: Not late-enabling -Xcheck:jni (already on) 2020-07-07 18:13:51.704 16572-16572/? I/.coilexperimen: Unquickening 12 vdex files! 2020-07-07 18:13:51.708 16572-16572/? W/.coilexperimen: Unexpected CPU variant for X86 using defaults: x86 2020-07-07 18:13:51.928 16572-16572/com.mjob.coilexperiment D/NetworkSecurityConfig: No Network Security Config specified, using platform default 2020-07-07 18:13:51.928 16572-16572/com.mjob.coilexperiment D/NetworkSecurityConfig: No Network Security Config specified, using platform default 2020-07-07 18:13:51.950 16572-16597/com.mjob.coilexperiment D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so 2020-07-07 18:13:51.959 16572-16597/com.mjob.coilexperiment D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so 2020-07-07 18:13:51.966 16572-16597/com.mjob.coilexperiment D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so 2020-07-07 18:13:52.039 16572-16572/com.mjob.coilexperiment I/TetheringManager: registerTetheringEventCallback:com.mjob.coilexperiment 2020-07-07 18:13:52.103 16572-16572/com.mjob.coilexperiment W/.coilexperimen: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 2020-07-07 18:13:52.104 16572-16572/com.mjob.coilexperiment W/.coilexperimen: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) 2020-07-07 18:13:52.150 16572-16595/com.mjob.coilexperiment D/HostConnection: HostConnection::get() New Host Connection established 0xee053030, tid 16595 2020-07-07 18:13:52.169 16572-16595/com.mjob.coilexperiment D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0 2020-07-07 18:13:52.174 16572-16595/com.mjob.coilexperiment W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 2020-07-07 18:13:52.176 16572-16595/com.mjob.coilexperiment D/EGL_emulation: eglCreateContext: 0xedea9f30: maj 3 min 0 rcv 3 2020-07-07 18:13:52.177 16572-16595/com.mjob.coilexperiment D/EGL_emulation: eglMakeCurrent: 0xedea9f30: ver 3 0 (tinfo 0xee1b2d90) (first time) 2020-07-07 18:13:52.193 16572-16595/com.mjob.coilexperiment I/Gralloc4: mapper 4.x is not supported 2020-07-07 18:13:52.196 16572-16595/com.mjob.coilexperiment D/HostConnection: createUnique: call 2020-07-07 18:13:52.197 16572-16595/com.mjob.coilexperiment D/HostConnection: HostConnection::get() New Host Connection established 0xee052970, tid 16595 2020-07-07 18:13:52.197 16572-16595/com.mjob.coilexperiment D/eglCodecCommon: allocate: Ask for block of size 0x100 2020-07-07 18:13:52.215 16572-16595/com.mjob.coilexperiment D/eglCodecCommon: allocate: ioctl allocate returned offset 0x3fdbe2000 size 0x2000 2020-07-07 18:13:52.234 16572-16595/com.mjob.coilexperiment D/HostConnection: HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_gles_max_version_3_0

Version Android 30 io.coil-kt:coil-base:0.11.0 io.coil-kt:coil-video:0.11.0 Device is a Pixel 3A XL virtual device

mamadou94Diop commented 4 years ago

I am sorry !! By mistake I submitted the issue without finishing fill the form

colinrtwhite commented 4 years ago

Hmm it looks like the logs didn't capture the exception. Can you add logger(DebugLogger() to your ImageLoader and re-run the code and post the exception? The stack trace should be logged with the tag RealImageLoader.

mamadou94Diop commented 4 years ago

Indeed, you were right! By adding that line in my image loader creation, the exception was displayed. 2020-07-08 10:01:59.084 17524-17524/com.mjob.coilexperiment I/RealImageLoader: 🚨 Failed - http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4 - java.lang.IllegalArgumentException: could not access http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4 2020-07-08 10:01:59.087 17524-17524/com.useradgents.coilexperiment E/RealImageLoader: java.lang.IllegalArgumentException: could not access http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4 at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:342) at coil.fetch.VideoFrameUriFetcher.setDataSource(VideoFrameFetcher.kt:63) at coil.fetch.VideoFrameUriFetcher.setDataSource(VideoFrameFetcher.kt:48) at coil.fetch.VideoFrameFetcher.fetch$suspendImpl(VideoFrameFetcher.kt:99) at coil.fetch.VideoFrameFetcher.fetch(Unknown Source:0) at coil.RealImageLoader$loadData$2.invokeSuspend(RealImageLoader.kt:327) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:738) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

It does not manage to access to this video url meanwhile this is a valid uri with a file having compatible extension, I tried with another video : http://videocdn.bodybuilding.com/video/mp4/62000/62792m.mp4 with the same exception thrown. By the way, my intent is just to do a poc showing that lib handles easily gif, image and video. So if you have a good URI for video, I am willing to take it.

colinrtwhite commented 4 years ago

Maybe it's due to using HTTP instead of HTTPS? Either way, Coil only supports decoding video frames from local files/uris. If you need a video to test, you could copy the video from the sample app.

mamadou94Diop commented 4 years ago

Yesterday I cheated by replacing that url by HTTPS but I got the same error. So can we expect a disclaimer on documentation section about video frames stating that currently remote video frames access is not possible?

colinrtwhite commented 4 years ago

There's already a disclaimer in the docs: Video frame decoding is only supported for Files and Uris (content and file schemes only).

mamadou94Diop commented 4 years ago

My bad. So can we expect in future releases to support remote URIs with HTTP/HTTPS schemes ?

colinrtwhite commented 4 years ago

Unfortunately, I don't think it's likely. If you're interested, I wrote up my thoughts here, but basically the Android APIs require a local file and Coil intentionally abstracts the data source from the Decoder.

mamadou94Diop commented 4 years ago

I got answers on my doubts, I can close that issue. Thank you!!