大佬教程收集整理的这篇文章主要介绍了ios – AV基金会动画从未开始播放,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试过不同类型的动画,不知道我做错了什么.
任何帮助将非常感激.
代码:
-(void) createCompositionWithPicture { AVMutableComposition* composition = [AVMutableComposition composition]; NSString *videoPath = [[NSBundle mainBundle] pathForresource:@"Movie" ofType:@"m4v"]; NSLog(@"Path: %@",videoPath); NSURL *videoURL = [[NSURL alloc] initFileURLWithPath:videoPath]; AVURLAsset *videoAsset = [AVURLAsset URLAssetWithURL:videoURL options:nil]; AVMutableCompositionTrack *videoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid]; [videoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero,videoAsset.duration) ofTrack:[[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectATindex:0] atTime:kCMTimeZero error:nil]; // Create an AVMutableVideoCompositionLayerinstruction for the video track. AVMutableVideoCompositioninstruction *maininstruction = [AVMutableVideoCompositioninstruction videoCompositioninstruction]; maininstruction.timeRange = CMTimeRangeMake(kCMTimeZero,videoAsset.duration); AVMutableVideoCompositionLayerinstruction *videolayerinstruction = [AVMutableVideoCompositionLayerinstruction videoCompositionLayerinstructionWithAssetTrack:videoTrack]; // Setup video composition AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition]; videoComposition.renderSize = CGSizeMake(videoTrack.naturalSize.width,videoTrack.naturalSize.height); videoComposition.frameDuration = CMTimeMake(1,30); maininstruction.layerinstructions = [NSArray arrayWithObject:videolayerinstruction]; videoComposition.instructions = [NSArray arrayWithObject:maininstruction]; NSLog(@"Width: %f Height: %f",videoTrack.naturalSize.width,videoTrack.naturalSize.height); // Setup animation layer UIImage* image = [UIImage imagenamed:@"dogge_icon.png"]; CALayer *animationLayer = [CALayer layer]; animationLayer.frame = CGRectMake(0,image.size.width,image.size.height); [animationLayer setMasksToBounds:YES]; [animationLayer setContents: (id)image.CGImage]; // Add animation CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; animation.duration=5.0; animation.autoreverses=YES; animation.fromValue = [NSnumber numberWithFloat:1.0f]; animation.toValue = [NSnumber numberWithFloat:2.0f]; animation.repeatCount=10; animation.beginTime = AVCoreAnimationBeginTimeAtZero; [animationLayer addAnimation:animation forKey:@"scale"]; NSLog(@"animationLayer animations: %@",[animationLayer animationKeys]); // Build layer hierarchy CALayer *parentLayer = [CALayer layer]; CALayer *videoLayer = [CALayer layer]; parentLayer.frame = CGRectMake(0,videoTrack.naturalSize.height); videoLayer.frame = CGRectMake(0,videoTrack.naturalSize.height); [parentLayer addSublayer:videoLayer]; [parentLayer addSublayer:animationLayer]; videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer]; // Export AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:composition presetName:AVAssetExportPresetHighestQuality]; NSString *exportVideoPath = [STPFileUtilities getPathToFileIn: NSDocumentDirectory WithName: @"composition.mov"]; [STPFileUtilities deleteFileIfExists:exportVideoPath]; NSURL *exportURL = [NSURL fileURLWithPath:exportVideoPath]; exportSession.outputURL = exportURL; exportSession.outputFileType = AVFileTypeQuickTimeMovie; exportSession.videoComposition = videoComposition; [exportSession exportAsynchronouslyWithCompletionHandler:^{ switch (exportSession.status) { case AVAssetExportSessionStatusFailed:{ NSLog(@"FAIL: %@",exportSession.error); break; } case AVAssetExportSessionStatusCompleted: { NSLog (@"succesS"); } }; }]; }
以上是大佬教程为你收集整理的ios – AV基金会动画从未开始播放全部内容,希望文章能够帮你解决ios – AV基金会动画从未开始播放所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。