A wechat like video trim time view.
- left and right time control
- custom your left side bar and right
- support setup maximum duration and minimum duration
- export video file from your time crop setting
NSString *path = [[NSBundle mainBundle] pathForResource:@"videoName"
ofType:@"MP4"];
YGCTrimVideoView *ygcTrimView = [[YGCTrimVideoView alloc] initWithFrame:CGRectMake(0, 75, self.view.bounds.size.width, 80)
assetUR:[NSURL fileURLWithPath:path]];
[self.view addSubview:self.ygcTrimView];
That's all
- (id)initWithFrame:(CGRect)frame
leftControlImage:(UIImage *)leftImage
rightControlImage:(UIImage *)rightImage
centerRangeImage:(UIImage *)centerImage
sideBarWidth:(CGFloat)sidebarWidth;
leftImage
you could setup your left sidebar with a imagerightImage
same as leftImagecenterRangeImage
the border image around the slider, maybe required set the image's resize insetsideBarWidth
the control bar width
just setup the property maxSeconds
and minSeconds
.
// min duration is 2 and max duration is 10
self.ygcTrimView.minSeconds = 2;
self.ygcTrimView.maxSeconds = 10;
in the delegate funtion
- (void)dragActionEnded:(AVMutableComposition *)asset
every time your finished dragging the control bar YGCTrimView will generate a AVMutableCompsition.You could create a AVPlayer and play the composition directly. like
- (void)dragActionEnded:(AVMutableComposition *)asset {
self.playerItem = [[AVPlayerItem alloc] initWithAsset:asset];
[self.player replaceCurrentItemWithPlayerItem:self.playerItem];
[self.player play];
}
YGCTrimVideoView support two ways to export a video file.
First Method
- (void)dragActionEnded:(AVMutableComposition *)asset;
get a AVMutableComposition from the delegate function. An AVMutableComposition is an AVAsset.So you could use AVExportSession to export a video file from AVMutableComposition.
Second Method
- (void)exportVideo:(YGCExportFinished)finishedBlock;
you could use the function directly to export a video file .The finishedBlock will give you the video url that from the sandbox.
In your podfile.
pod 'YGCTrimVideoView', '~> 0.2.3'
then pod install
if you get an error " Unable to satisfy the following requirements", please use
pod install --repo-update
- iOS 10 or higher
- zang qilong - zangqilong
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
This project is licensed under the MIT License.