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.isAudioSlow() = getMimeType().startsWith("audio")
fun File.getMimeType(default: String = ""): String {
fun File.getMimeType(default: String = getDefaultMimeType()): String {
return try {
val retriever = MediaMetadataRetriever()
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 {
val retriever = MediaMetadataRetriever()
retriever.setDataSource(path)