Skip to content

Commit

Permalink
Fix VideoFrameUriFetcher attempting to handle http URIs. (#734)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrtwhite authored Apr 23, 2021
1 parent 968dd1c commit 5641dd2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ class VideoFrameFetcherTest {
fetcher = VideoFrameUriFetcher(context)
}

@Test
fun uriFetcherHandlesContentScheme() {
val uri = "content://test/scheme/BigBuckBunny.mp4".toUri()
assertTrue(fetcher.handles(uri))
}

@Test
fun uriFetcherDoesNotHandleHttpScheme() {
val uri = "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4".toUri()
assertFalse(fetcher.handles(uri))
}

@Test
fun noSetFrameTime() {
// MediaMetadataRetriever.getFrameAtTime does not work on the emulator pre-API 23.
Expand Down
6 changes: 5 additions & 1 deletion coil-video/src/main/java/coil/fetch/VideoFrameFetcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class VideoFrameUriFetcher(private val context: Context) : VideoFrameFetcher<Uri

override fun handles(data: Uri): Boolean {
val fileName = data.lastPathSegment
return fileName != null && SUPPORTED_FILE_EXTENSIONS.any { fileName.endsWith(it, true) }
return fileName != null &&
data.scheme !in UNSUPPORTED_SCHEMES &&
SUPPORTED_FILE_EXTENSIONS.any { fileName.endsWith(it, true) }
}

override fun MediaMetadataRetriever.setDataSource(data: Uri) {
Expand Down Expand Up @@ -85,6 +87,8 @@ abstract class VideoFrameFetcher<T : Any>(context: Context) : Fetcher<T> {
// https://developer.android.com/guide/topics/media/media-formats#video-formats
@JvmField internal val SUPPORTED_FILE_EXTENSIONS = arrayOf(".3gp", ".mkv", ".mp4", ".ts", ".webm")

@JvmField internal val UNSUPPORTED_SCHEMES = arrayOf("http", "https")

internal const val ASSET_FILE_PATH_ROOT = "android_asset"

const val VIDEO_FRAME_MICROS_KEY = VideoFrameDecoder.VIDEO_FRAME_MICROS_KEY
Expand Down

0 comments on commit 5641dd2

Please # to comment.