[英]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.我正在使用 Firebase 作为数据库,用户可以在其中上传图像或视频,因此我从我的数据库中获取 URL,因此我获得了两个 URL,其中一个可以是视频或图像,因此我可以做些什么来检测 URL。
Let Suppose this is the URL.假设这是 URL。 This is the example URL.
这是示例 URL。 NOTE URL can be different
注意 URL 可以不同
any help will be appreciated任何帮助将不胜感激
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.注意:某些 URL 没有像
PNG
、MP4
、JPG
等扩展名。 I am saying this because I have a some URLs with no extension related to mp4 or png etc.我这么说是因为我有一些没有与 mp4 或 png 等相关的扩展名的 URL。
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.当您将图像/视频保存到数据库时,我建议您将一列命名为“类型”,并为图像保留 0,为视频保留 1。 This way you can recognise the type easily.
这样您就可以轻松识别类型。
You may need to tweak UI little bit.您可能需要稍微调整 UI。 You can provide an option to capture image from UI and launch camera app only to capture image.
您可以提供从 UI 捕获图像的选项,并仅启动相机应用程序来捕获图像。 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.
如上所述在 firebase db 中保存该类型值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.