Anybody know how to upload a video to firebase? I used this link: record video in swift
I managed to record and have a playback in same view Gif of my video on giphy
The code to play the video I just recorded is:
@IBAction func playVideo(sender: AnyObject) {
print("Play a video")
// Find the video in the app's document directory
let paths = NSSearchPathForDirectoriesInDomains(
NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let documentsDirectory: AnyObject = paths[0]
let dataPath = documentsDirectory.stringByAppendingPathComponent(saveFileName)
let videoAsset = (AVAsset(URL: NSURL(fileURLWithPath: dataPath)))
let playerItem = AVPlayerItem(asset: videoAsset)
print(playerItem)
let videoView = UIView(frame: CGRectMake(self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.width, self.view.bounds.height))
let pathURL = NSURL.fileURLWithPath(dataPath)
moviePlayer = MPMoviePlayerController(contentURL: pathURL)
if let player = moviePlayer {
player.view.frame = videoView.bounds
player.prepareToPlay()
player.scalingMode = .AspectFill
videoView.addSubview(player.view)
}
moviePlayer!.view.frame = videoPreview.bounds
moviePlayer!.view.center = CGPointMake(CGRectGetMidX(videoPreview.bounds), CGRectGetMidY(videoPreview.bounds))
videoPreview.addSubview((moviePlayer?.view)!)
}
And I know how to upload a PICTURE to Firebase I need to use NSString
like this:
var base64String : NSString!
//let pic = UIImagePNGRepresentation(UIImage(named: "3")!)
let picture = UIImageJPEGRepresentation(self.profilePictureImageView.image!, 0.1)!
self.base64String = picture.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength)
let updatedProfileInfo = [
"provider": USER_REF.authData.provider,
"email": self.emailTextfield.text!,
"Username": self.usernameTextfield.text!,
"ProfilePicture" : self.base64String,
"ProfileDescription" : self.bioDescriptionTextfield.text
]
USER_REF.updateChildValues(updatedProfileInfo)
But how do you do with videos?
Thank you