我想在Sprite Kit中创建一个视频序列,并使用以下代码:
@interface VideScreenNode()
@end
@implementation VideScreenNode
- (void)setupVideoSequence
{
AVPlayerItem * intro = [AVPlayerItem playerItemWithURL:[self geturlFromFileName:@"Video1" andType:@"mp4"]];
AVPlayerItem * video1 = [AVPlayerItem playerItemWithURL:[self geturlFromFileName:@"Video2" andType:@"mp4"]];
AVPlayerItem * video2 = [AVPlayerItem playerItemWithURL:[self geturlFromFileName:@"Video3" andType:@"mp4"]];
AVPlayerItem * video3 = [AVPlayerItem playerItemWithURL:[self geturlFromFileName:@"Video4" andType:@"mp4"]];
AVPlayerItem * video4 = [AVPlayerItem playerItemWithURL:[self geturlFromFileName:@"Video5" andType:@"mp4"]];
AVPlayerItem * outro = [AVPlayerItem playerItemWithURL:[self geturlFromFileName:@"Video6" andType:@"mp4"]];
AVQueuePlayer * queuePlayer = [[AVQueuePlayer alloc] initWithItems:@[intro, video1, video2, video3, video4, outro]];
SKVideoNode * sequenceNode = [[SKVideoNode alloc] initWithAVPlayer: queuePlayer];
sequenceNode.position = CGPointMake(512, 384);
[sequenceNode play];
[self addChild:sequenceNode];
}
#pragma mark - helper
- (NSURL *)geturlFromFileName:(NSString *)name
andType:(NSString *)type
{
return [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: name ofType:type]];
}
视频序列工作正常,但每个剪辑之间有一个小的中断。如何实现无缝过渡?
提前致谢。
答案 0 :(得分:2)
您想要在AVQueuePlayer
上添加一个电话。如:
[queuePlayer prerollAtRate:float completionHandler:^(BOOL finished)completionHandler];
这会将文件加载到内存中并准备播放。这将对性能产生影响,具体取决于剪辑的大小。它应该平滑你拥有的过渡。但是,您需要注意,好像status
属性不是AVPlayerStatusReadyToPlay
,这会失败。