当我点击播放视频时,它显示如下。想知道为什么。没有显示错误。我确实导入了 AVKit 和 AVFoundation。另外,我在我的设备和模拟器中进行了测试。还是不行。有什么建议么?非常感谢。
**Print log**
//<PFFile: 0x79d472f0>
//https://files.parsetfss.com/d9cdffff-4a1f-4bd9-b6ee-e60c07d49236/tfss-7e1636b9-5701-4737-9fa6-10609aec89e8-adsVido
//<AVPlayer: 0x786f39b0>
// Click cell to play video.
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
if adsVideoArray[indexPath.row] != nil {
let theVideo:PFFile = adsVideoArray[indexPath.row]!
print(theVideo)
let url:NSURL = NSURL(string: theVideo.url!)!
theVideo.getDataInBackgroundWithBlock({ (data:NSData?, error: NSError?) -> Void in
if error == nil {
let player = AVPlayer(URL: url)
print(url)
print(player)
let playerController = AVPlayerViewController()
playerController.player = player
self.presentViewController(playerController, animated: true) {
player.play()
}
}
})
}
}
// load data from parse
func loadAdsFromParse() {
adsVideoArray.removeAll(keepCapacity: false)
let query = PFQuery(className: "user_ads")
query.findObjectsInBackgroundWithBlock({ (objects: [PFObject]?, error: NSError?) -> Void in
for object in objects! {
self.adsVideoArray.append(object.objectForKey("video") as? PFFile)
}
dispatch_async(dispatch_get_main_queue()) {
self.adsCollectionView.reloadData()
}
})
}
// the way to save video
self.tempVideo = info[UIImagePickerControllerMediaURL] as! NSURL!
let videoData = NSData(contentsOfFile:self.tempVideo.relativePath!)
let videoFile:PFFile = PFFile(name:"adsVido", data:videoData!)!
detailsObj["video"] = videoFile
detailsObj.saveInBackgroundWithBlock{ ... }
// I tried to play the video before upload it to Parse. It works.
func playImageTapped(pressed: UIGestureRecognizer) {
let player = AVPlayer(URL: tempVideo)
let playerController = AVPlayerViewController()
playerController.player = player
self.presentViewController(playerController, animated: true) {
player.play()
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let mediaType = info[UIImagePickerControllerMediaType] as! NSString
self.tempVideo = videoAdded