我在播放介绍场景中的视频时遇到问题。我已将我的视频添加到场景中,并且播放正常。我只是想让它一次又一次地重复。有什么办法可以设置这个视频在它结束后自动播放吗?
这是我添加视频的方式:
SKVideoNode *videoNode = [SKVideoNode videoNodeWithVideoFileNamed:@"game1.m4v"];
videoNode.position = CGPointMake(150, 180);
videoNode.size = CGSizeMake(150, 150);
[self addChild:videoNode];
[videoNode play];
任何帮助表示赞赏。
最佳答案
使用以下命令初始化您的 SKVideoNode:
- (instancetype)initWithAVPlayer:(AVPlayer *)player
设置 AVPlayer 时使用:
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[avPlayer currentItem]];
这将防止玩家在最后暂停。
在通知中:
-(void)playerItemDidReachEnd:(NSNotification *)notification {
AVPlayerItem *p = [notification object];
[p seekToTime:kCMTimeZero];
}
这将倒带电影。
(感谢 Bastian 对 this question 的回答)
关于sprite-kit - 在 Sprite 套件中永远播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28814929/