码迷,mamicode.com
首页 > 其他好文 > 详细

UIVideoEditorController的使用

时间:2014-12-23 19:34:41      阅读:471      评论:0      收藏:0      [点我收藏+]

标签:

UIVideoEditorController是一个视频编辑器,通过系统提供的UI界面来剪切视频或者降低视频的画质.UIVideoEditorController对象处理用户的交互并且提供把编辑后的视频的文件系统路径提供给UIVideoEditorControllerDelegate对象.

UIVideoEditorController支持能够支持视频编辑的设备.

UIVideoEditorControllerUIImagePickerController的主要区别是前者能提供视频的编辑,后者主要用于录像或者视频的选择.

实现代码:

//遵守协议
class ViewController: UIViewController, UIVideoEditorControllerDelegate, UINavigationControllerDelegate {
    var editVideoViewController:UIVideoEditorController!
    
    @IBAction func editVideoTapped(sender: AnyObject) {
        //取到Video的资源
        let videoPath = NSBundle.mainBundle().pathForResource("show", ofType: "mov");
        
        //创建之前要确定是否能够打开视频文件,如果能打开才创建UIVideoEditController
        if UIVideoEditorController.canEditVideoAtPath(videoPath!) {
            //创建UIVideoEditController
            editVideoViewController = UIVideoEditorController()
            //设置delegate
            editVideoViewController.delegate = self
            //设置要编辑的视频地址
            editVideoViewController.videoPath = videoPath!
            //设置视频最长时间
            editVideoViewController.videoMaximumDuration = 30
            //设置视频的画质(如果TypeHigh,则画质不变)
            editVideoViewController.videoQuality = .TypeHigh
            //present UIVideoEditController
            presentViewController(editVideoViewController, animated: true, completion: {})
        }
    }

    //UIVideoEditorController自己不会主动小时,所以delegate的回调方法的一个主要作用是消除UIVideoEditorController,
    //编辑成功后的Video被保存在沙盒的临时目录中
    func videoEditorController(editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
        print("editedVideopath = \(editedVideoPath)")
        dismissViewControllerAnimated(true, completion: {})
    }
    //编辑失败后调用的方法
    func videoEditorController(editor: UIVideoEditorController, didFailWithError error: NSError) {
        print("error=\(error.description)")
        dismissViewControllerAnimated(true, completion: {})
    }
    //编辑取消后调用的方法
    func videoEditorControllerDidCancel(editor: UIVideoEditorController) {
        dismissViewControllerAnimated(true, completion: {})
    }
}

效果图:

技术分享




UIVideoEditorController的使用

标签:

原文地址:http://blog.csdn.net/lcl130/article/details/42105579

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!