iOS - 使用苹果自带的UIVideoEditController进行视频编辑
UIVideoEditorController类包含了由系统提供的界面,使用户可以交互式的剪切视频。UIVideoEditorController对象处理用户的交互并且提供把编辑后的视频的文件系统路径提供给UIVideoEditorControllerDelegate对象.
UIVideoEditorController只支持能够支持视频编辑的设备.
我们设置好它的delegate及videoPath属性,并将其展示出来。(经过videoQuality属性,也可以通过这个类将视频重新编码成质量较低的格式)
@property(nullable, nonatomic,assign) id <UINavigationControllerDelegate, UIVideoEditorControllerDelegate> delegate; @property(nonatomic, copy) NSString *videoPath; // 视频路径
@property(nonatomic) NSTimeInterval videoMaximumDuration; // default value is 10 minutes. set to 0 to specify no maximum duration. @property(nonatomic) UIImagePickerControllerQualityType videoQuality; // default value is UIImagePickerControllerQualityTypeMedium
UIVideoEditorController和UIImagePickerController的主要区别是前者能提供视频的编辑,后者主要用于录像或者视频的选择.
UIVideoEditorController视频编辑器所用的delegate回调与UIImagePickerController类相似,这些回调方法分别来处理成功、失败、取消这三种情况:
videoEditorController:didSaveEditedVideoToPath:
videoEditorController: didFailWithError:
videoEditorControllerDidCancel:
#import <AVFoundation/AVFoundation.h>
#import "ViewController.h"
@interface ViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIVideoEditorControllerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.
}
- (IBAction)click:(UIButton *)sender {
UIImagePickerController *myImagePickerController = [[UIImagePickerController alloc] init];
myImagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
myImagePickerController.mediaTypes =[UIImagePickerController availableMediaTypesForSourceType:myImagePickerController.sourceType];
myImagePickerController.delegate = self; myImagePickerController.editing = NO;
[self presentViewController:myImagePickerController animated:YES completion:nil];
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[picker dismissViewControllerAnimated:YES completion:^{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:@"public.movie"]) {
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
UIVideoEditorController *editVC; // 检查这个视频资源能不能被修改
if ([UIVideoEditorController canEditVideoAtPath:videoURL.path]) {
editVC = [[UIVideoEditorController alloc] init];
editVC.videoPath = videoURL.path;
editVC.delegate = self;
}
[self presentViewController:editVC animated:YES completion:nil];
}
}];
}
//编辑成功后的Video被保存在沙盒的临时目录中
- (void)videoEditorController:(UIVideoEditorController *)editor didSaveEditedVideoToPath:(NSString *)editedVideoPath {
NSLog(@"+++++++++++++++%@",editedVideoPath);
}
// 编辑失败后调用的方法
- (void)videoEditorController:(UIVideoEditorController *)editor didFailWithError:(NSError *)error {
NSLog(@"%@",error.description);
}
//编辑取消后调用的方法
- (void)videoEditorControllerDidCancel:(UIVideoEditorController *)editor {}
@end
这是swift版本:
class ViewController: UIViewController, UIVideoEditorControllerDelegate, UINavigationControllerDelegate,UIImagePickerControllerDelegate {
var editVideoViewController:UIVideoEditorController!
@IBAction func editVideoTapped(sender: AnyObject) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
let types = UIImagePickerController.availableMediaTypesForSourceType(.Camera)!
imagePicker.mediaTypes = [types[1]]//kUTTypeMovie
self.presentViewController(imagePicker, animated: true, completion: nil)
}
//MARK: - UIImagePickerControllerDelegate
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
picker.dismissViewControllerAnimated(true) { () -> Void in
let mediaType:String = info[UIImagePickerControllerMediaType] as! String
if mediaType == "public.movie" {
let url: NSURL = info[UIImagePickerControllerMediaURL] as! NSURL
let editVideoViewController = UIVideoEditorController()
//设置delegate
editVideoViewController.delegate = self
//设置要编辑的视频地址
editVideoViewController.videoPath = videoPath!
self.presentViewController(editVideoViewController, animated: true, completion: nil)
}
}
}
//MARK: - UIVideoEditorControllerDelegate
//编辑成功后的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: {})
}
}
这是效果图 :
开源链接分享
使用UIVideoEditController进行视频编辑是基于苹果封装好的编辑类,要是我们实现自定义视频截取,就要自己写了,在这里分享一个视频编辑并裁剪的一个第三方,地址是 https://github.com/itsmeichigo/ICGVideoTrimmer.git,使用效果不错!
iOS - 使用苹果自带的UIVideoEditController进行视频编辑的更多相关文章
- ios开发中如何调用苹果自带地图导航
前段时间一直在赶项目,在外包公司工作就是命苦,天天加班不说,工作都是和工期合同挂钩的,稍微逾期就有可能被扣奖金,不谈这些伤脑筋的事情了,让我们说说iOS开发中如何调用苹果手机自带的地图. 学习如逆水行 ...
- iOS苹果自带UIMenuController
一.UIMenuController认识 1.默认情况下,UITextView / UITextFiled / UIWebView 都有苹果自带的有UIMenuController功能 2.UITex ...
- iOS之苹果和百度地图的使用
iOS中使用较多的3款地图,google地图.百度地图.苹果自带地图(高德).其中苹果自带地图在中国使用的是高德的数据.苹果在iOS 6之后放弃了使用谷歌地图,而改用自家的地图.在国内使用的较多的就是 ...
- 【iOS】苹果,百度Map定位使用与总结
iOS中使用较多的3款地图,google地图.百度地图.苹果自带地图(高德).当中苹果自带地图在中国使用的是高德的数据.苹果在iOS 6之后放弃了使用谷歌地图,而改用自家的地图.在国内使用的较多的就是 ...
- 操作系统-移动操作系统-百科: iOS(苹果公司的移动操作系统)
ylbtech-操作系统-移动操作系统-百科: iOS(苹果公司的移动操作系统) iOS是由苹果公司开发的移动操作系统.苹果公司最早于2007年1月9日的Macworld大会上公布这个系统,最初是设计 ...
- ios(苹果公司的移动操作系统)
iOS是由苹果公司开发的移动操作系统. 苹果公司最早于2007年1月9日的Macworld大会上公布这个系统,最初是设计给iPhone使用的, 后来陆续套用到iPod touch.iPad以及Appl ...
- IOS开发苹果官方Sample Code及下载地址
IOS开发苹果官方Sample Code及下载地址 在线浏览地址:https://developer.apple.com/library/ios/navigation/#section=Resourc ...
- iOS开发苹果内购的介绍与实现
1.iOS开发苹果内购的介绍 1.1 介绍 苹果规定,凡是虚拟的物品(例如:QQ音乐的乐币)进行交易时,都必须走苹果的内购通道,苹果要收取大约30%的抽成,所以不允许接入第三方的支付方式(微信.支付宝 ...
- iOS面试题整理带答案
iOS面试题整理带答案 找工作,面试是避免不了的! 而技术开发面试,问一些技术相关的问题是必须的,最新的技术可能人人都趋之若鹜,但有些原理和基础的也希望都有了解. 这里整理了一些iOS相关 ...
随机推荐
- python获取两个dict的不同
参数: dict1, dict2 需求:如果dict1和dict2中有不同的key,那么返回这个(key, dict1[key]):如果dict1和dict2中有相同的key,但是value不同,返回 ...
- vs2012更改默认开发环境
1.在菜单栏里找到“Tools”(工具),选择下面的“Import and Export Settings”(导入和导出设置),如图1所示: 图1 2.弹出如下界面,按提示选择你需要 ...
- 谈谈入门iOS的经验吧
前言 近期忙完项目比較闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助.博主非科班出身,一些计算机术语上的不专业欢迎大家指正. 我是学微电子的.大四的时候找了一家深圳的专业对口的 ...
- iOS_UITextField 基本操作
基本操作 UITextField *userNameTextField = [[UITextField alloc] init]; userNameTextField.frame = CGRectMa ...
- AppStore应用转让流程
可能大家都有这样的情况,给公司客户开发一个ios app的前期阶段是先发布在自己公司的开发者账户上面的,而不是直接发布在客户的开发者账号上面,这个到后期的话就有一个转让的事情,俗称“过户”. 步骤如下 ...
- iOS开发-Autolayout小结
昨天重点学习了下Autolayout,把以前没有吃透的概念重新理解了下,现在感觉整个人都是棒棒哒. 上一个项目是使用计算坐标代码的方式来布局UI界面,这种方式的缺点在于当苹果发布新尺寸设备时需要重写代 ...
- iOS开发--提交应用Your binary is not optimized for iPhone 5
ERROR ITMS-: "Your binary is not optimized for iPhone 5 - New iPhone apps and app updates submi ...
- 【LeetCode OJ】Search Insert Position
题目:Given a sorted array and a target value, return the index if the target is found. If not, return ...
- 【LeetCode OJ】Remove Duplicates from Sorted Array
题目:Given a sorted array, remove the duplicates in place such that each element appear only once and ...
- 查看sql server日志
如果是查询当前已经连接到服务器的用户 select loginame, * from master.dbo.sysprocesses 查看sql 的操作日志记录 SELECT * From ::fn_ ...