显示视频,添加UITextfield并将其保存到iphone的专辑中

时间:2015-09-01 06:13:49

标签: ios swift video avfoundation snapchat

我正在尝试制作一个大冒险。目前我正在研究相机的录像部分。我拍了一段视频,制作了一个网址,然后设置MPMoviePlayerController来播放它。将UITextField添加到MPMoviePlayerController.view并保存整个内容。问题是,它与捕获静止图像不同,如下所示:

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)

目前我有这个,它只保存视频而不保存uitextfield:

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()
    }
})

我认为会有一个等同于静止图像保存方式的视频,但是你没有保存MPMoviePlayerController,在我的函数中它被称为“播放器”或者是player.view,但是播放器的URL,可以使用player.contentURL访问(很高兴知道,但在这种情况下,冗余)或outputFileURL。有没有人在过去使用任何基于相机的应用程序实现此功能?有谁知道如何实现这一目标?

0 个答案:

没有答案