如何检查图片或视频的网址? [英] How to check url is image or video?
本文介绍了如何检查图片或视频的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我 fetch
API响应并以swift解析选择URL.但我需要检查的是图片网址还是视频网址:
I fetch
API response and parse pick url in swift . but i need to check is image url or video url :
如果我获取图片网址,则显示图片,如果获取视频网址,则播放视频:
If i get image url then show image and if get video url then play video :
if let url = postMedia?.url{
//need to check here
}
例如
这是我的视频网址:
https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
https://clips.vorwaerts-gmbh.de/big_buck_bunny.mov
这是图片网址:
https://clips.vorwaerts-gmbh.de/big_buck_bunny.png
https://clips.vorwaerts-gmbh.de/big_buck_bunny.jpg
注意:我知道如何显示图像和播放视频
note : i know how to show image and play video
推荐答案
您可以检查以下图像
let url1 : String = "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
let imageExtensions = ["png", "jpg", "gif"]
//...
// Iterate & match the URL objects from your checking results
let url: URL? = NSURL(fileURLWithPath: url1) as URL
let pathExtention = url?.pathExtension
if imageExtensions.contains(pathExtention!)
{
print("Image URL: \(String(describing: url))")
// Do something with it
}else
{
print("Movie URL: \(String(describing: url))")
}
与您可以观看视频相同
这篇关于如何检查图片或视频的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文