add a helper function for checking simple mime type

This commit is contained in:
tibbi 2017-03-23 00:09:21 +01:00
parent a817a8caef
commit e557ac3ede

View file

@ -13,7 +13,7 @@ fun File.isImageSlow() = absolutePath.isImageFast() || getMimeType().startsWith(
fun File.isVideoSlow() = absolutePath.isVideoFast() || getMimeType().startsWith("video") fun File.isVideoSlow() = absolutePath.isVideoFast() || getMimeType().startsWith("video")
fun File.isAudioSlow() = getMimeType().startsWith("audio") fun File.isAudioSlow() = getMimeType().startsWith("audio")
fun File.getMimeType(default: String = ""): String { fun File.getMimeType(default: String = getDefaultMimeType()): String {
return try { return try {
val retriever = MediaMetadataRetriever() val retriever = MediaMetadataRetriever()
retriever.setDataSource(path) retriever.setDataSource(path)
@ -23,6 +23,8 @@ fun File.getMimeType(default: String = ""): String {
} }
} }
fun File.getDefaultMimeType() = if (isVideoFast()) "video/*" else "image/*"
fun File.getDuration(): String { fun File.getDuration(): String {
val retriever = MediaMetadataRetriever() val retriever = MediaMetadataRetriever()
retriever.setDataSource(path) retriever.setDataSource(path)