Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Get the video URL
- let videoURL = info[UIImagePickerControllerMediaURL] as? NSURL
- //Create PFFile with NSData from URL
- let data = NSData(contentsOfURL: videoURL!)
- videoFile = PFFile(data: data!, contentType: "video/mp4")
- //Save PFFile first, then save the PFUser
- PFUser.currentUser()?.setObject(videoFile!, forKey: "profileVideo")
- videoFile?.saveInBackgroundWithBlock({ (succeeded, error) -> Void in
- print("saved video")
- PFUser.currentUser()?.saveInBackgroundWithBlock({ (succeeded, error) -> Void in
- if succeeded && error == nil {
- print("user saved")
- //Hide progress bar
- UIView.animateWithDuration(0.5, animations: { () -> Void in
- self.progressBar.alpha = 0
- }, completion: { (bool) -> Void in
- self.progressBar.removeFromSuperview()
- })
- }else{
- //Show error if the save failed
- let message = error!.localizedDescription
- let alert = UIAlertController(title: "Uploading profile picture error!", message: message, preferredStyle: UIAlertControllerStyle.Alert)
- let dismiss = UIAlertAction(title: "OK", style: UIAlertActionStyle.Cancel, handler: nil)
- alert.addAction(dismiss)
- self.presentViewController(alert, animated: true, completion: nil)
- }
- })
- }, progressBlock: { (progress) -> Void in
- self.progressBar.setProgress(Float(progress)/100, animated: true)
- })
- //Get URL from my current user
- self.videoFile = PFUser.currentUser()?.objectForKey("profileVideo") as? PFFile
- self.profileVideoURL = NSURL(string: (self.videoFile?.url)!)
- //Create AVPlayerController
- let playerController = AVPlayerViewController()
- //Set AVPlayer URL to where the file is stored on the sever
- let avPlayer = AVPlayer(URL: self.profileVideoURL)
- playerController.player = avPlayer
- //Present the playerController
- self.presentViewController(playerController, animated: true, completion: { () -> Void in
- playerController.player?.play()
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement