如何知道提供的 URL 是 Android Studio 中的图像或视频
How to know that provided URL is Image or Video in Android Studio
我使用 Firebase 作为数据库,用户可以在其中上传图像或视频,所以我从我的数据库中获取 URL,所以我得到两个 URL,其中一个可以是视频或图像那么我该怎么做才能检测到 URL.
让我们假设这是URL。
This is the example URL. NOTE URL can be different
任何帮助将不胜感激
已编辑
为了更好地理解,我将提供一些示例代码:
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.
我建议您在将 image/video 保存到数据库时,将一列命名为“类型”,并为图像保留 0,为视频保留 1。这样您就可以轻松识别类型。
您可能需要稍微调整一下 UI。您可以提供从 UI 捕获图像的选项,并启动相机应用程序仅捕获图像。同样提供一个选项来只捕获视频。通过这种方式,您可以确保前端用户一次捕获图像或视频。如上所述将该类型值保存在 firebase db 中。
我使用 Firebase 作为数据库,用户可以在其中上传图像或视频,所以我从我的数据库中获取 URL,所以我得到两个 URL,其中一个可以是视频或图像那么我该怎么做才能检测到 URL.
让我们假设这是URL。 This is the example URL. NOTE URL can be different
任何帮助将不胜感激
已编辑
为了更好地理解,我将提供一些示例代码:
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.
我建议您在将 image/video 保存到数据库时,将一列命名为“类型”,并为图像保留 0,为视频保留 1。这样您就可以轻松识别类型。
您可能需要稍微调整一下 UI。您可以提供从 UI 捕获图像的选项,并启动相机应用程序仅捕获图像。同样提供一个选项来只捕获视频。通过这种方式,您可以确保前端用户一次捕获图像或视频。如上所述将该类型值保存在 firebase db 中。