在精灵套件中永远播放视频

Adr*_*n P 5 sprite-kit skvideonode

我在介绍场景中播放视频时遇到问题.我已将我的视频添加到场景中并且播放正常.我只是希望它一次又一次地重复.是否有任何方法可以将此视频设置为在结束后自动播放?

这就是我添加视频的方式:

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

任何帮助表示赞赏.

san*_*ony 6

使用以下命令初始化SKVideoNode:

- (instancetype)initWithAVPlayer:(AVPlayer *)player
Run Code Online (Sandbox Code Playgroud)

设置AVPlayer时使用:

avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; 

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playerItemDidReachEnd:)
                                             name:AVPlayerItemDidPlayToEndTimeNotification
                                           object:[avPlayer currentItem]];
Run Code Online (Sandbox Code Playgroud)

这样可以防止玩家在结束时暂停.

在通知中:

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

这将回放电影.

(感谢巴斯蒂安这个问题的回答)