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

Media Picker: Choose From Device: Fix Video thumbnails do not load #15411

Merged
merged 7 commits into from
Oct 12, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor: Extract file size from URL into separate method
  • Loading branch information
ashiagr committed Oct 4, 2021
commit 3c3a3fc9d0c386cb2f5347c481225cbf15ca348d
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@ class VideoLoader
var length = MIN_SIZE
withContext(bgDispatcher) {
try {
val url = URL(filePath)

val urlConnection = url.openConnection()
for ((key, value) in authenticationUtils.getAuthHeaders(filePath).entries) {
urlConnection.addRequestProperty(key, value)
}

length = urlConnection.contentLength
if (length <= MIN_SIZE) {
length = urlConnection.getHeaderFieldInt("Content-Length", MIN_SIZE)
}
length = getSizeFromURL(URL(filePath))
} catch (ioe: IOException) {
appLogWrapper.e(T.MEDIA, "Failed to load video thumbnail: ${ioe.stackTrace}")
}
Expand All @@ -56,6 +46,19 @@ class VideoLoader
}
}

private fun getSizeFromURL(url: URL): Int {
val urlConnection = url.openConnection()
for ((key, value) in authenticationUtils.getAuthHeaders(url.toString()).entries) {
urlConnection.addRequestProperty(key, value)
}

var length = urlConnection.contentLength
if (length <= MIN_SIZE) {
length = urlConnection.getHeaderFieldInt("Content-Length", MIN_SIZE)
}
return length
}

companion object {
private const val MIN_SIZE = 0
private const val SIZE_LIMIT_10_MB = 10485760
Expand Down