【发布时间】:2013-10-31 13:35:11
【问题描述】:
我在使动画使用 AVPlayer 时间而不是系统时间时遇到问题。同步层无法正常工作,动画在系统时间而不是播放器时间上保持同步。我知道玩家确实在玩。如果我将 CACurrentMediaTime() 传递给 beginTime,动画会立即开始,因为它应该在不同步时开始。
编辑
我可以看到从一开始就处于最终状态的红色方块,这意味着动画在开始时已经到达结束,因为它是在系统时间而不是 AVPlayerItem 时间同步的。
// play composition live in order to modifier
AVPlayerItem * playerItem = [AVPlayerItem playerItemWithAsset:composition];
AVPlayer * player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer * playerLayer = [AVPlayerLayer playerLayerWithPlayer:player ];
playerLayer.frame = [UIScreen mainScreen].bounds;
if (!playerItem) {
NSLog(@"playerItem empty");
}
// dummy time
playerItem.forwardPlaybackEndTime = totalDuration;
playerItem.videoComposition = videoComposition;
CALayer * aLayer = [CALayer layer];
aLayer.frame = CGRectMake(100, 100, 60, 60);
aLayer.backgroundColor = [UIColor redColor].CGColor;
aLayer.opacity = 0.f;
CAKeyframeAnimation * keyframeAnimation2 = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
keyframeAnimation2.removedOnCompletion = NO;
keyframeAnimation2.beginTime = 0.1;
keyframeAnimation2.duration = 4.0;
keyframeAnimation2.fillMode = kCAFillModeBoth;
keyframeAnimation2.keyTimes = @[@0.0, @1.0];
keyframeAnimation2.values = @[@0.f, @1.f];
NSLog(@"%f current media time", CACurrentMediaTime());
[aLayer addAnimation:keyframeAnimation2
forKey:@"opacity"];
[self.parentLayer addSublayer:aLayer];
AVSynchronizedLayer * synchronizedLayer =
[AVSynchronizedLayer synchronizedLayerWithPlayerItem:playerItem];
synchronizedLayer.frame = [UIScreen mainScreen].bounds;
[synchronizedLayer addSublayer:self.parentLayer];
[playerLayer addSublayer:synchronizedLayer];
【问题讨论】:
-
你知道如何在创建视频的过程中给两个图像之间的过渡效果。如果你知道怎么可能,请帮助我..
-
玩两个calayer的alpha,以图片为内容。
-
在从图像数组创建视频时添加 CALayer 的位置。我正在从此链接创建视频。ios.biomsoft.com/2012/02/01/create-movie-from-array-of-images
-
在您的示例中,您从图像创建电影,您使用传递给 AVPlayer 的图像创建 AVAsset,而我只是创建包含图像的 CALayer,这些图像作为子层添加到 AVSynchronizedLayer,就像一个 CALayer它的时间线与播放 AVAsset 的 AVPlayer 的时间同步。 AVPlayer->AVAsset AVSynchornizedLayer->CALayer
-
你能给我举个例子吗?请
标签: ios iphone animation avfoundation