Ios AVSynchronizedLayer未同步动画
我在使用AVPlayer时间而不是系统时间制作动画时遇到问题。同步层不能正常工作,动画在系统时间而不是播放器时间保持同步。我知道这名球员确实打球。如果我将caccurrentmediatime()传递给beginTime,动画会立即开始,就像它在不同步时应该做的那样 编辑 我可以看到红方块从一开始就处于其最终状态,这意味着动画在一开始就达到了它的终点,因为它是在系统时间而不是AVPlayerItem时间同步的Ios AVSynchronizedLayer未同步动画,ios,iphone,animation,avfoundation,Ios,Iphone,Animation,Avfoundation,我在使用AVPlayer时间而不是系统时间制作动画时遇到问题。同步层不能正常工作,动画在系统时间而不是播放器时间保持同步。我知道这名球员确实打球。如果我将caccurrentmediatime()传递给beginTime,动画会立即开始,就像它在不同步时应该做的那样 编辑 我可以看到红方块从一开始就处于其最终状态,这意味着动画在一开始就达到了它的终点,因为它是在系统时间而不是AVPlayerItem时间同步的 // play composition live in order to mo
// 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];
解决方案是,
AVSynchronizedLayer
在模拟器上不起作用,但在设备上可以正常工作。您知道如何在创建视频时在两个图像之间提供过渡效果。如果您知道如何实现,请帮助我..使用两个calayer的alpha,并将图像作为其内容。在何处添加calayer当从图像数组创建视频时。我正在从此链接创建视频。在您的示例中,您从图像创建电影,您使用传递给AVPlayer的图像创建AVAsset,而我只是创建包含图像的CALayer,这些图像作为子层添加到AVSynchronizedLayer,与CALayer类似,只是其时间线是同步的当一个AVP玩家玩AVAsset的时候。AVPlayer->AVAsset AvsynchornizLayer->Calayer你能给我举个例子吗