簡體   English   中英

如何知道提供的 URL 是 Android Studio 中的圖像還是視頻

[英]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 沒有像PNGMP4JPG等擴展名。 我這么說是因為我有一些沒有與 mp4 或 png 等相關的擴展名的 URL。

當您將圖像/視頻保存到數據庫時,我建議您將一列命名為“類型”,並為圖像保留 0,為視頻保留 1。 這樣您就可以輕松識別類型。

您可能需要稍微調整 UI。 您可以提供從 UI 捕獲圖像的選項,並僅啟動相機應用程序來捕獲圖像。 同樣提供僅捕獲視頻的選項。 通過這種方式,您可以確保前端用戶一次捕獲圖像或視頻。 如上所述在 firebase db 中保存該類型值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM