Sprite Kit 中的视频序列会导致混乱的中断
Video sequence in Sprite Kit leads to messy interruptions
我想在 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]];
}
视频序列工作得很好,但每个剪辑之间有一个小中断。如何实现无缝过渡?
提前致谢。
您想在您拥有的 AVQueuePlayer
上添加一个呼叫。如:
[queuePlayer prerollAtRate:float completionHandler:^(BOOL finished)completionHandler];
这会将文件加载到内存中并准备播放。这将对性能产生影响,具体取决于剪辑的大小。它应该平滑你的过渡。但是,您需要注意,如果 status
属性 不是 AVPlayerStatusReadyToPlay
,这将失败。
我想在 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]];
}
视频序列工作得很好,但每个剪辑之间有一个小中断。如何实现无缝过渡?
提前致谢。
您想在您拥有的 AVQueuePlayer
上添加一个呼叫。如:
[queuePlayer prerollAtRate:float completionHandler:^(BOOL finished)completionHandler];
这会将文件加载到内存中并准备播放。这将对性能产生影响,具体取决于剪辑的大小。它应该平滑你的过渡。但是,您需要注意,如果 status
属性 不是 AVPlayerStatusReadyToPlay
,这将失败。