我正在開發一款適用於iOS Runnign的Swift應用,可以在播放器中播放一些視頻和圖像;iOS Swift,如何爲不同的文件擴展名聲明?
我打電話是爲了喜歡的視頻文件:
videoView.displayMode = GVRWidgetDisplayMode.fullscreen
和圖像:
imageView.displayMode = GVRWidgetDisplayMode.fullscreen
我想有一個if語句,等等;
如果正在調用的文件是.png,則通過imageViewer啓動它;
上面添加的代碼是被調用:
如果文件是MP4,通過視頻查看
我在本地調用文件啓動它(
let urlString = "\(postslogin[selectedIndexPath].link)"
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let fileName = urlString as NSString;
let filePath="\(documentsPath)/\(fileName.lastPathComponent)";
let fileURL = NSURL.init(fileURLWithPath: filePath)
let request = NSURLRequest.init(url: fileURL as URL)
被perviously通過下載)來自super.viewDidLoad。
任何建議將超級!
謝謝:) :)
---編輯新建---
到目前爲止,我已經嘗試:
let urlString = "\(postslogin[selectedIndexPath].link)"
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
let fileName = urlString as NSString;
let filePath="\(documentsPath)/\(fileName.lastPathComponent)";
let fileURL = NSURL.init(fileURLWithPath: filePath)
let request = NSURLRequest.init(url: fileURL as URL)
if (fileURL.pathExtension == "jpg") {
imageVRView.load(UIImage(named: "\(documentsPath)/\(fileName.lastPathComponent)"),
of: GVRPanoramaImageType.mono)
imageVRView.displayMode = GVRWidgetDisplayMode.fullscreen
}
else if (fileURL.pathExtension == "mp4") {
videoVRView.displayMode = GVRWidgetDisplayMode.fullscreen
videoVRView.load(from: URL((fileURLWithPath: filePath))
)
}
沒有成功:(:(
你有沒有試過這個?http://stackoverflow.com/a/26707509/6203030 –
我需要它在super.viewDidLoad()而不是像這樣的解決方案嗎? – tibewww
如果您正在下載的文件的名稱具有擴展名,請查找點位置或獲取最後三個字符的子字符串,並使用該子字符串,您應該可以在所需的選項之間切換。 –