我正在尝试在swift应用程序中找到一种从parse.com数据库加载youtube URL字符串的方法。我有它,所以当用户点击一个显示视频的按钮时,它将加载连接到URL的视频。我似乎无法找到如何使这项工作。有关如何编码的任何想法?
在数据库中我有一个名为Products的类,而视频的列名是ProductVideo,而应用中的按钮叫做productVideo。
编辑:
//展开当前对象对象
if let object = currentObject {
productName.text = object["ProductName"] as? String
productDescription.text = object["ProductDescription"] as! String productCategory.text = object["ProductCategory"] as? String
videoStatus.text = object["VideoStatus"] as? String var initialThumbnail = UIImage(named: "question")
ProductImage.image? = initialThumbnail!
if let thumbnail = object["ProductImage"] as? PFFile {
ProductImage.file = thumbnail
ProductImage.loadInBackground() if self.videoStatus.text == "None"{ self.productVideo.hidden = true
self.videoView.hidden = true
}
编辑:
//展开当前对象对象
if let object = currentObject {
productName.text = object["ProductName"] as? String
productDescription.text = object["ProductDescription"] as! String productCategory.text = object["ProductCategory"] as? String
videoStatus.text = object["VideoStatus"] as? String
let youtubeURL = currentObject["ProductVideo"] as! String
let url = NSURL(string: youtubeURL)
if UIApplication.sharedApplication().canOpenURL(url!) {
UIApplication.sharedApplication().openURL(url!)
}
var initialThumbnail = UIImage(named: "question")
ProductImage.image? = initialThumbnail!
if let thumbnail = object["ProductImage"] as? PFFile {
ProductImage.file = thumbnail
ProductImage.loadInBackground()
if self.videoStatus.text == "None"
{
self.productVideo.hidden = true
self.videoView.hidden = true
}
答案 0 :(得分:0)
如果你有像你说的那样的网址,那么你可以
let youtubeURL = parseObjeect["ProductVideo"] as String
然后
let url = NSURL(string: youtubeURL)
if UIApplication.sharedApplication().canOpenURL(url!) {
UIApplication.sharedApplication().openURL(url!)
}
注意:如果用户安装了应用,这将在Safari或YouTube中打开Youtube视频。