更新时间 : 2021-07-12 13:48:53
轨道,分为多媒体轨道,贴纸轨道,文字轨道和音频轨道。 需要通过SXEditManager 或 SXComposite 来初始化。
SXTrack
轨道基类,包含所有轨道共有的属性。
其中轨道在 SXEditManager 的展示时间主要由三个属性决定,startTime,offsetTime和duration。
displayTime = startTime + offsetTime。
可以参考文档Start Time, In Point, Out Point讲解,其中inPoint对应displayTime。
SXAudioTrack
音频轨道,可以修改音量,音调,淡入淡出,速度等属性。
SXRenderTrack
渲染轨道,是可视化轨道类的基类,主要包含一些视觉信息,如位置类的信息,透明度等。
渲染轨道可以添加关键帧动画。
//example:
//添加关键帧
[renderTrack addKeyframeData:SXKeyframeTypePosition time:_keyFrameMill value:[NSValue valueWithCGPoint:renderTrack.position] options:SXKeyFrameOptionsLinear];
[renderTrack addKeyframeData:SXKeyframeTypeScale time:_keyFrameMill value:[NSValue valueWithCGPoint:renderTrack.scale] options:SXKeyFrameOptionsLinear];
[renderTrack addKeyframeData:SXKeyframeTypeRotation time:_keyFrameMill value:[NSNumber numberWithFloat:renderTrack.rotation] options:SXKeyFrameOptionsLinear];
[renderTrack addKeyframeData:SXKeyframeTypeOpacity time:_keyFrameMill value:[NSNumber numberWithFloat:renderTrack.opacity] options:SXKeyFrameOptionsLinear];
//修改关键帧对应的值
[renderTrack setKeyframeData:SXKeyframeTypeRotation time:_keyFrameMill value:[NSNumber numberWithFloat:_rotation / M_PI * 180]];
//移除关键帧
[renderTrack removeKeyframeData:SXKeyframeTypeScale time:_keyframeTime];
多媒体轨道
//example:
SXMediaTrack *track = (SXMediaTrack *)_model.track;
SXResource *resource = [[SXResource alloc] initWithType:SXResourceTypeFilter path:filterPath];
SXFilterEffect *filter = [track addFilter:resource index:0];
[filter setFollowType:SXEffectTimeFollowWholeProcess];
//example:
SXShape *shape = [[SXShape alloc] init];
[shape circle:CGPointMake(0.0, 0.0) radius:radius];
[shape transform:CGAffineTransformTranslate(CGAffineTransformIdentity, mediaTrack.getTrackSize.width / 2, mediaTrack.getTrackSize.height / 2)];
//设置蒙版形状
[mediaTrack setMaskShape:shape];
//example:
- (void)updateSize:(CGSize)size transfrom:(CGAffineTransform)transform {
if (_currentTrackModel.track) {
SXMediaTrack *mediaTrack = (SXMediaTrack *)_currentTrackModel.track;
//裁剪素材
[mediaTrack cropMediaWithSize:size transform:transform];
}
}
if (transitionPath) {
int error;
//添加转场
SXResource *resource = [[SXResource alloc] initWithType:SXResourceTypeTransition path:_transitionPath];
[track setTransition:resource] duration:1.0];
}else {
//移除转场
[track removeTransition];
}
文字轨道
//example:
int error;
//设置文字气泡
SXResource *resource = [[SXResource alloc] initWithType:SXResourceTypeTextBubble path:bubblePath];
[_textTrack setBubble:resource];
//example:
if (_model.inTextAnimationEffect) {
//移除文字动画
[_textTrack removeTextAnimation:_model.inTextAnimationEffect.getEffectId];
_model.inTextAnimationEffect = nil;
}
if (_model.outTextAnimationEffect) {
[_textTrack removeTextAnimation:_model.outTextAnimationEffect.getEffectId];
_model.outTextAnimationEffect = nil;
}
SXResource *resource = [[SXResource alloc] initWithType:SXResourceTypeTextAnimation path:animationPath];
if (_model.loopTextAnimationEffect) {
//给文字动画设置新的资源包
[_model.loopTextAnimationEffect setResource:resource];
}else {
//添加文字动画
_model.loopTextAnimationEffect = [_textTrack addTextAnimation:resource index:0];
}
_model.loopTextAnimationEffect.durationOfOneCycle = _timeSliderView.value;
[_model.loopTextAnimationEffect setFollowType: SXEffectTimeFollowTypeFollowWholeProcess];
贴纸轨道
//example:
if (_model.inTrackAnimationEffect) {
//移除轨道动画
[_sitckerTrack removeTrackAnimation:_model.inTrackAnimationEffect.getEffectId];
_model.inTrackAnimationEffect = nil;
}
if (_model.outTrackAnimationEffect) {
[_sitckerTrack removeTrackAnimation:_model.outTrackAnimationEffect.getEffectId];
_model.outTrackAnimationEffect = nil;
}
SXResource *resource = [[SXResource alloc] initWithType:SXResourceTypeTrackAnimation path:animationPath];
if (_model.loopTrackAnimationEffect) {
//给轨道动画设置新的资源包
[_model.loopTrackAnimationEffect setResource:resource];
}else {
//添加轨道动画
_model.loopTrackAnimationEffect = [_sitckerTrack addTrackAnimation:resource index:0];
}
_model.loopTrackAnimationEffect.durationOfOneCycle = _timeSliderView.value;
[_model.loopTrackAnimationEffect setFollowType: SXEffectTimeFollowTypeFollowWholeProcess];
轨道,分为多媒体轨道,贴纸轨道,文字轨道和音频轨道。 需要通过SXEditManager 或 SXComposite 来初始化。
SXTrack
轨道基类,包含所有轨道共有的属性。
其中轨道在 SXEditManager 的展示时间主要由三个属性决定,startTime,offsetTime和duration。
displayTime = startTime + offsetTime。
可以参考文档Start Time, In Point, Out Point讲解,其中inPoint对应displayTime。
SXAudioTrack
音频轨道,可以修改音量,音调,淡入淡出,速度等属性。
SXRenderTrack
渲染轨道,是可视化轨道类的基类,主要包含一些视觉信息,如位置类的信息,透明度等。
渲染轨道可以添加关键帧动画。
//example:
//添加关键帧
[renderTrack addKeyframeData:SXKeyframeTypePosition time:_keyFrameMill value:[NSValue valueWithCGPoint:renderTrack.position] options:SXKeyFrameOptionsLinear];
[renderTrack addKeyframeData:SXKeyframeTypeScale time:_keyFrameMill value:[NSValue valueWithCGPoint:renderTrack.scale] options:SXKeyFrameOptionsLinear];
[renderTrack addKeyframeData:SXKeyframeTypeRotation time:_keyFrameMill value:[NSNumber numberWithFloat:renderTrack.rotation] options:SXKeyFrameOptionsLinear];
[renderTrack addKeyframeData:SXKeyframeTypeOpacity time:_keyFrameMill value:[NSNumber numberWithFloat:renderTrack.opacity] options:SXKeyFrameOptionsLinear];
//修改关键帧对应的值
[renderTrack setKeyframeData:SXKeyframeTypeRotation time:_keyFrameMill value:[NSNumber numberWithFloat:_rotation / M_PI * 180]];
//移除关键帧
[renderTrack removeKeyframeData:SXKeyframeTypeScale time:_keyframeTime];
多媒体轨道
//example:
SXMediaTrack *track = (SXMediaTrack *)_model.track;
SXResource *resource = [[SXResource alloc] initWithType:SXResourceTypeFilter path:filterPath];
SXFilterEffect *filter = [track addFilter:resource index:0];
[filter setFollowType:SXEffectTimeFollowWholeProcess];
//example:
SXShape *shape = [[SXShape alloc] init];
[shape circle:CGPointMake(0.0, 0.0) radius:radius];
[shape transform:CGAffineTransformTranslate(CGAffineTransformIdentity, mediaTrack.getTrackSize.width / 2, mediaTrack.getTrackSize.height / 2)];
//设置蒙版形状
[mediaTrack setMaskShape:shape];
//example:
- (void)updateSize:(CGSize)size transfrom:(CGAffineTransform)transform {
if (_currentTrackModel.track) {
SXMediaTrack *mediaTrack = (SXMediaTrack *)_currentTrackModel.track;
//裁剪素材
[mediaTrack cropMediaWithSize:size transform:transform];
}
}
if (transitionPath) {
int error;
//添加转场
SXResource *resource = [[SXResource alloc] initWithType:SXResourceTypeTransition path:_transitionPath];
[track setTransition:resource] duration:1.0];
}else {
//移除转场
[track removeTransition];
}
文字轨道
//example:
int error;
//设置文字气泡
SXResource *resource = [[SXResource alloc] initWithType:SXResourceTypeTextBubble path:bubblePath];
[_textTrack setBubble:resource];
//example:
if (_model.inTextAnimationEffect) {
//移除文字动画
[_textTrack removeTextAnimation:_model.inTextAnimationEffect.getEffectId];
_model.inTextAnimationEffect = nil;
}
if (_model.outTextAnimationEffect) {
[_textTrack removeTextAnimation:_model.outTextAnimationEffect.getEffectId];
_model.outTextAnimationEffect = nil;
}
SXResource *resource = [[SXResource alloc] initWithType:SXResourceTypeTextAnimation path:animationPath];
if (_model.loopTextAnimationEffect) {
//给文字动画设置新的资源包
[_model.loopTextAnimationEffect setResource:resource];
}else {
//添加文字动画
_model.loopTextAnimationEffect = [_textTrack addTextAnimation:resource index:0];
}
_model.loopTextAnimationEffect.durationOfOneCycle = _timeSliderView.value;
[_model.loopTextAnimationEffect setFollowType: SXEffectTimeFollowTypeFollowWholeProcess];
贴纸轨道
//example:
if (_model.inTrackAnimationEffect) {
//移除轨道动画
[_sitckerTrack removeTrackAnimation:_model.inTrackAnimationEffect.getEffectId];
_model.inTrackAnimationEffect = nil;
}
if (_model.outTrackAnimationEffect) {
[_sitckerTrack removeTrackAnimation:_model.outTrackAnimationEffect.getEffectId];
_model.outTrackAnimationEffect = nil;
}
SXResource *resource = [[SXResource alloc] initWithType:SXResourceTypeTrackAnimation path:animationPath];
if (_model.loopTrackAnimationEffect) {
//给轨道动画设置新的资源包
[_model.loopTrackAnimationEffect setResource:resource];
}else {
//添加轨道动画
_model.loopTrackAnimationEffect = [_sitckerTrack addTrackAnimation:resource index:0];
}
_model.loopTrackAnimationEffect.durationOfOneCycle = _timeSliderView.value;
[_model.loopTrackAnimationEffect setFollowType: SXEffectTimeFollowTypeFollowWholeProcess];