我有一个应用程序,允许用户以可变组合录制视频。我想设置一些会出现的文本,然后以我在导出后用户播放它时设置的间隔更改。
例如,如果第一个单词是“dog”,那么我想设置它,以便“cat”在 X 秒后替换该字符串,然后在 X 秒后被另一个单词替换。
我的视频是使用 AVExportSession 从 AVMutableComposition 导出的,我的文字将使用添加到其中的 CATextlayer 添加,如下所示:
//code to setup AVMutableComposition
...
//code to setup CATextLayer and AVMutableVideoComposition
CALayer *animatedTitleLayer = [CALayer layer];
CATextLayer *titleLayer = [[CATextLayer alloc] init];
titleLayer.string = @"Text I want to change at an interval";
titleLayer.alignmentMode = kCAAlignmentCenter;
titleLayer.bounds = CGRectMake(150, 50, 124, 354);
titleLayer.position = CGPointMake(120, 270);
titleLayer.bounds = CGRectIntegral(CGRectMake(0, 0, 250, 150));
titleLayer.opacity = 1;
titleLayer.backgroundColor = [UIColor purpleColor].CGColor;
[animatedTitleLayer addSublayer:titleLayer];
animatedTitleLayer.position = CGPointMake(40, 5);
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
parentLayer.frame = CGRectMake(0, 0, 320, 480);
videoLayer.frame = CGRectMake(0, 0, 320, 480);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:animatedTitleLayer];
parentLayer.preferredTransform = rotationTransform;
AVMutableVideoComposition *videoComposition;
videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
//code to setup AVExportSession
...
我的问题是:如何使文本更改为我设置为我指定的字符串的间隔?
任何建议将不胜感激。