[英]How to know that provided URL is Image or Video in Android Studio
我正在使用 Firebase 作为数据库,用户可以在其中上传图像或视频,因此我从我的数据库中获取 URL,因此我获得了两个 URL,其中一个可以是视频或图像,因此我可以做些什么来检测 URL。
假设这是 URL。 这是示例 URL。 注意 URL 可以不同
任何帮助将不胜感激
为了更好地理解,我将提供一些示例代码:
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.
}
...
注意:某些 URL 没有像
PNG
、MP4
、JPG
等扩展名。 我这么说是因为我有一些没有与 mp4 或 png 等相关的扩展名的 URL。
当您将图像/视频保存到数据库时,我建议您将一列命名为“类型”,并为图像保留 0,为视频保留 1。 这样您就可以轻松识别类型。
您可能需要稍微调整 UI。 您可以提供从 UI 捕获图像的选项,并仅启动相机应用程序来捕获图像。 同样提供仅捕获视频的选项。 通过这种方式,您可以确保前端用户一次捕获图像或视频。 如上所述在 firebase db 中保存该类型值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.