简体   繁体   English

如何知道提供的 URL 是 Android Studio 中的图像还是视频

[英]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任何帮助将不胜感激

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.注意:某些 URL 没有像PNGMP4JPG等扩展名。 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.

相关问题 如何在android studio中为图像添加URL? - How to add URL to an image in android studio? 如何通过URL的视频视图实时知道视频在android VideoView中的启动时间? - How can I know the real time the video starts in android VideoView with the video view from URL? 使用 Android Studio 编写应用程序以观看由相机提供的实时视频 - Writing an App with Android Studio to watch a Live Video which is provided by a Camera 如果我知道它的 URL,如何获取图像大小? 安卓(Java) - How to get image size if I know its URL? Android (java) android 工作室的 ffmpeg 中的视频叠加图像 - Overlay image on video in ffmpeg for android studio Android Studio,如何通过url获取可绘制图像 - Android Studio, how to get image in drawable through url 如何将URL图像传递到另一个活动的Android Studio - How to Pass URL Image to another activity Android studio 如何为android提供的不同日期和时间格式的视频添加时间戳? - How to add timestamp to video with different date & time format provided by android? 如何知道 Android Studio 中输入的字母是否为大写? - How to know if the typed alphabet is uppercase in Android Studio? 在Android Studio中通过网址制作图片滑块 - Make image slider from url in android studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM