0

I want to create a video sequence in Sprite Kit and use the following code:

@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]];
}

The video sequence works just fine, but there is a small interruption between each clip. How do I achieve a seamless transition?

Thanks in advance.

Objective D
  • 799
  • 5
  • 16

1 Answers1

2

You want to add in a call on the AVQueuePlayer that you have. Such as:

[queuePlayer prerollAtRate:float completionHandler:^(BOOL finished)completionHandler];

This will load the files into memory and prepare them to play. This will have an impact on performance, depending on the size of the clips. It should smooth out the transitions that you have. However, you will need to watch out, as if the status property is not AVPlayerStatusReadyToPlay, this will fail.

Gliderman
  • 1,195
  • 9
  • 18