2016-04-19 16 views
2

ビデオをfirebaseにアップロードする方法を知っている人はいますか? 私は、このリンクを使用:record video in swiftビデオを録画してFirebaseにアップロード

私はちょうど録画したビデオを再生するコードがある同じビューで再生を記録し、持っているGif of my video on giphy

を管理:

@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)!) 
} 

そして、どのように私が知っていますD

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) 

をしかし、あなたをどのように行う:私はこのようなNSStringを使用する必要がFirebaseに写真をアップロードビデオ付き?

はありがとう

+0

があるFirebaseデータベースに映像を保存しようとすると、悪い考え。 30分から私の答えを見てください:http://stackoverflow.com/questions/36718006/handling-image-store-to-firebase-with-swift –

+1

よろしくお願いします。なぜそれは悪い考えですか?ビデオストレージサービスをどこで見つけることができますか?あなたはlite youtubeを意味しますか? –

+2

FirebaseはJSONデータベースです。ビデオ(画像のような)は本質的にJSONデータではありません。使用するビデオストレージサービスの推奨事項はここではスタックオーバーフローではありませんが、いくつかのGoogle検索では一生のうちにリストを取得する必要があります。 –

答えて

2

これだった私のデバイスで動画や画像を選択し、FireabaseにアップロードするUIImagePickerオブジェクトクラスを使用しての私の解決策:

@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 
    present(picker, animated: true, completion: nil) 
} 

// 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 
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { 

    if let videoURL = info[UIImagePickerControllerMediaURL] as? NSURL { 
     // we selected a video 
     print("Here's the file URL: ", videoURL) 

     // Where we'll store the video: 
     let storageReference = FIRStorage.storage().reference().child("video.mov") 

     // Start the video storage process 
     storageReference.putFile(videoURL as URL, metadata: nil, completion: { (metadata, error) in 
      if error == nil { 
       print("Successful video upload") 
      } else { 
       print(error?.localizedDescription) 
      } 
     }) 

     } 
      //Dismiss the controller after picking some media 
      dismiss(animated: true, completion: nil) 
    } 
+1

これは、写真ギャラリーではなくドキュメントディレクトリURLで動作しますか?例。ファイル:///var/mobile/Containers/Data/Application/E9319B41-05BF-4F5C-8D58-999CE0087D8F/Documents/temporary_video.mp4 – omarojo

+0

確かめてください!メディアがどこにあるかを示すURLを指すことができる限り、それをサーバーにアップロードできます。それを撃つ、それがどうなるか教えてください:) –

関連する問題