catch exceptions at getting file mimetype

This commit is contained in:
tibbi 2017-06-07 07:50:29 +02:00
parent c3bca54f54
commit 86712ffe89
2 changed files with 9 additions and 6 deletions

View file

@ -29,5 +29,5 @@ ext {
propMinSdkVersion = 16
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '2.20.0'
propVersionName = '2.20.1'
}

View file

@ -18,11 +18,14 @@ fun File.isVideoSlow() = absolutePath.isVideoFast() || getMimeType().startsWith(
fun File.isAudioSlow() = getMimeType().startsWith("audio")
fun File.getMimeType(default: String = getDefaultMimeType()): String {
val extension = MimeTypeMap.getFileExtensionFromUrl(absolutePath)
return if (extension != null) {
MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
} else
default
try {
val extension = MimeTypeMap.getFileExtensionFromUrl(absolutePath)
if (extension != null) {
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
}
} catch (ignored: Exception) {
}
return default
}
fun File.getDefaultMimeType() = if (isVideoFast()) "video/*" else if (isImageFast()) "image/*" else if (isGif()) "image/gif" else ""