我使用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.
}
...
注意:有些URLS没有扩展,如
PNG
、MP4
、JPG
等。我之所以这么说,是因为我有一些与mp4或png等相关的没有扩展名的URL。
发布于 2021-10-23 07:34:36
我建议您在将图像/视频保存到数据库中时,使用一个名为"type“的列,并为图像保留0,为视频保留1。这样你就能很容易地识别出这种类型。
您可能需要稍微调整UI。您可以提供一个从UI获取图像的选项,并启动相机应用程序来捕获图像。类似地,提供一个只捕获视频的选项。通过这种方式,您可以确保在前端用户一次捕获图像或视频。如前所述,将该类型值保存在消防基准数据库中。
https://stackoverflow.com/questions/69685850
复制相似问题