Record Video and upload to Firebase
有人知道如何将视频上传到 Firebase 吗?
我使用了这个链接:在 swift
中录制视频
我设法在 giphy 上录制并在同一视图 Gif 中播放我的视频
播放我刚刚录制的视频的代码是:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
@IBAction func playVideo(sender: AnyObject) { print("Play a video") // Find the video in the app’s document directory let videoAsset = (AVAsset(URL: NSURL(fileURLWithPath: dataPath))) 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!.view.frame = videoPreview.bounds |
而且我知道如何将图片上传到 Firebase 我需要像这样使用
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
var base64String : NSString!
//let pic = UIImagePNGRepresentation(UIImage(named:"3")!) self.base64String = picture.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding64CharacterLineLength) let updatedProfileInfo = [ |
但是你如何处理视频呢?
谢谢
这是我使用 UIImagePicker 对象类在我的设备中选择视频或图像并将其上传到 Fireabase 的解决方案:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
@IBAction func uploadButton(_ sender: Any) { // Configuration let picker = UIImagePickerController() picker.allowsEditing = true picker.delegate = self picker.mediaTypes = [kUTTypeImage as String, kUTTypeMovie as String] // Present the UIImagePicker Controller // The didFinishPickingMediaWithInfo let’s you select an image/video and let’s you decide what to do with it. In my example, I decided to convert the selected data into video and upload it to Firebase Storage if let videoURL = info[UIImagePickerControllerMediaURL] as? NSURL { // Where we’ll store the video: // Start the video storage process } |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/268637.html