Is there a way to check if the file I'm loading as a URI is a image or a video in android? I'm trying to dynamically loaded both images and videos into fragments for a list/detail view and need to tell them apart.
get(getArguments(). getString(ARG_ITEM_ID)). get(0)); ` where info_map is a map with (String, ArrayList<String>) pairings where get(0) gives the file name and get(1) right now gets a parameter from the xml for the video type.
php $finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension foreach (glob("*") as $filename) { echo finfo_file($finfo, $filename) . "\n"; } finfo_close($finfo); ?> Save this answer. Show activity on this post.
JPEGs offer you the most flexibility with raster editing and compression making them ideal for web images that need to be downloaded quickly. You want to print photos and/or artwork. At high resolution files with low compression, JPEGs are perfect for editing and then printing.
I'd check the mimeType and then check if it corresponds to an image or video.
A full example, for checking if a filepath is an image, would be:
public static boolean isImageFile(String path) { String mimeType = URLConnection.guessContentTypeFromName(path); return mimeType != null && mimeType.startsWith("image"); }
And for video:
public static boolean isVideoFile(String path) { String mimeType = URLConnection.guessContentTypeFromName(path); return mimeType != null && mimeType.startsWith("video"); }
If you are getting your Uri from a content resolver you can get the mime type using getType(Uri);
ContentResolver cR = context.getContentResolver(); String type = cR.getType(uri);
should get back something similar to "image/jpeg" which you can check against for your display logic.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With