lundi 3 août 2015

How can I save the videos that I'm recording?

I'm having trouble saving the videos that I'm recording. I can shoot, but I can not save them, just want to film and record videos in the library.

Can anyone help me?

 //My viewController

 import UIKit
 import MediaPlayer
 import MobileCoreServices
 import AVFoundation


 class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIGestureRecognizerDelegate {

let captureSession = AVCaptureSession()
var previewLayer : AVCaptureVideoPreviewLayer?
var captureDevice : AVCaptureDevice?

override func viewDidAppear(animated: Bool) {

    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {


        println("captureVideoPressed and camera available.")

        var imagePicker = UIImagePickerController()

        imagePicker.delegate = self
        imagePicker.sourceType = .Camera;
        imagePicker.mediaTypes = [kUTTypeMovie!]
        imagePicker.allowsEditing = false

        imagePicker.showsCameraControls = true


        self.presentViewController(imagePicker, animated: true, completion: nil)

    }

    else {
        println("Camera not available.")
    }
}

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


func imagePickerController(picker: UIImagePickerController!,  info: NSDictionary!) {

    let tempImage = info[UIImagePickerControllerMediaURL] as! NSURL!
    let pathString = tempImage.relativePath
    self.dismissViewControllerAnimated(true, completion: {})

    UISaveVideoAtPathToSavedPhotosAlbum(pathString, self, nil, nil)

}

}


  //My Library

  import UIKit;
  import MobileCoreServices

  class LibraryViewController: UIViewController, UINavigationControllerDelegate,UIImagePickerControllerDelegate {

@IBOutlet weak var myRecord: UIImageView!
@IBAction func aBottonPlay(sender: AnyObject) {
    var catchVideo = UIImagePickerController()
    catchVideo.delegate = self
    catchVideo.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
    catchVideo.mediaTypes = [kUTTypeMovie]
    self.presentViewController(catchVideo, animated: true, completion: nil)
}
override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
    myRecord.image = image
    self.dismissViewControllerAnimated(true, completion: nil)

}
}

Aucun commentaire:

Enregistrer un commentaire