Search code examples
objective-csprite-kitskvideonode

Stop and quit SKVideo


H! I'm using SKVideoNode to play a video on a project. The thing is that when I try to stop it and get back to the current actions sometimes it works but sometimes not.

Here is the code where I play it. Thanks in advance.

SKAction *actionPlayVideo = [SKAction runBlock:^{
     SKVideoNode *introVideoLevel1 = [SKVideoNode     videoNodeWithVideoFileNamed:@"escenario_intermedio.mov"];
    introVideoLevel1.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame));
    [introVideoLevel1 setName:@"IntroVideo"];
    introVideoLevel1.size = CGSizeMake(ipad_2_width, ipad_2_height);
    [self addChild: introVideoLevel1];
    [introVideoLevel1 play];
    }];

SKAction *actionStopVideo = [SKAction runBlock:^{
    dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        usleep(6900000);
        //[[self childNodeWithName:@"IntroVideo"] stop];
        [[self childNodeWithName:@"IntroVideo"] removeFromParent];
    });
}];

[self runAction:[SKAction sequence:@[actionPlayVideo, actionStopVideo]]];

Solution

  • Solved it! Just added another action (waitTime) between play and stop and removed the dispatch_async and the usleep