Play video forever in a set of sprites

I have a problem playing videos in my opening scene. I added my video to the scene and it plays great. I just want him to repeat over and over. is there any way to set this video to automatically play after it ends?

this is how i add the video:

SKVideoNode *videoNode = [SKVideoNode videoNodeWithVideoFileNamed:@"game1.m4v"]; videoNode.position = CGPointMake(150, 180); videoNode.size = CGSizeMake(150, 150); [self addChild:videoNode]; [videoNode play]; 

any help is appreciated.

+5
source share
1 answer

Initialize your SKVideoNode with

 - (instancetype)initWithAVPlayer:(AVPlayer *)player 

When setting up AVPlayer, use:

 avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:[avPlayer currentItem]]; 

this will prevent the player from pausing at the end.

In the notice:

 -(void)playerItemDidReachEnd:(NSNotification *)notification { AVPlayerItem *p = [notification object]; [p seekToTime:kCMTimeZero]; } 

it rewinds the film.

(Confirm Bastian for your answer to this question )

+6
source

Source: https://habr.com/ru/post/1214491/


All Articles