Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VideoFrameUriFetcher attempting to handle http URIs. #734

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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