Skip to content
Advertisement

How to know that provided URL is Image or Video in Android Studio

I am Using Firebase as Database where user can Upload Image or Video so I am Fetching URL from my database so I am getting two URLs one of them can be either video or image so what can I do to detect the URL.

Let Suppose this is the URL. This is the example URL. NOTE URL can be different

any help will be appreciated

Edited

for better understanding I will providing some example code:

MyUserModel model; //this is the model class where I can get the url in String

String Url = model.getUrl(); //its URL can be video or image

//Can I write something like this:

//does any method like this : isVideo();
// if the url is video then this function will return true else false;

if(isVideo(Url)){
 videoView.setVideoPath(Url); //and other stuffs
}else{
  Glide.with(context).load(Url).into(ImagView); //something like this.
}

 ...

NOTE : SOME URLS DON’T HAVE EXTENTIONS LIKE PNG, MP4, JPG ETC. I am saying this because I have a some URLs with no extension related to mp4 or png etc.

Advertisement

Answer

I will suggest you to have one column named as “type” and keep 0 for image and 1 for video when you are saving image/video into data base. This way you can recognise the type easily.

You may need to tweak UI little bit. You can provide an option to capture image from UI and launch camera app only to capture image. Similarly provide an option to capture only video. This way you can make sure at front end user is capturing either image or video at a time. Save that type value in firebase db as above.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement