I am trying to make a snapchat clone. Currently I am working on the camera's video recording portion. I take a video, make a url, and set an MPMoviePlayerController
to play it. Add a UITextField
to the MPMoviePlayerController.view and save the whole thing. The problem is, it is not the same as capturing a still image, shown here:
imageView.layer.addSublayer(captionField.layer)
UIGraphicsBeginImageContext(self.view.bounds.size)
imageView.layer.renderInContext(UIGraphicsGetCurrentContext())
image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let library:ALAssetsLibrary = ALAssetsLibrary()
var orientation: ALAssetOrientation = ALAssetOrientation(rawValue: image.imageOrientation.rawValue)!
library.writeImageToSavedPhotosAlbum(image.CGImage, orientation: orientation, completionBlock: nil)
Currently I have this, which saves only the video but not the uitextfield with it:
moviePlayer = MPMoviePlayerController(contentURL: outputFileURL)
player = moviePlayer!
player.view.frame = self.view.bounds
player.controlStyle = .None
player.repeatMode = .One
player.prepareToPlay()
player.scalingMode = .AspectFill
self.view.addSubview(player.view)
player.view.layer.addSublayer(captionField.layer)
UIGraphicsBeginImageContext(self.view.bounds.size)
player.view.layer.renderInContext(UIGraphicsGetCurrentContext())
UIGraphicsEndImageContext()
ALAssetsLibrary().writeVideoAtPathToSavedPhotosAlbum(outputFileURL, completionBlock: {
(assetURL:NSURL!, error:NSError!) in
if error != nil{
print(error)
} else {
self.resetButtons()
}
})
I assumed that there would be a video equivalent to the still image way of saving, but you don't save the MPMoviePlayerController
, in my function it is called "player" or the player.view, but the URL of the player, which can be accessed with player.contentURL, (nice to know, though in this case, redundant), or outputFileURL. Has anyone achieved this functionality with any camera-based applications in the past? Does anyone know how this can be achieved?