在 sprite kit 中永远播放视频 [英] play video forever in sprite kit
本文介绍了在 sprite kit 中永远播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的介绍场景中播放视频时遇到问题.我已将我的视频添加到场景中,并且可以正常播放.我只是希望它一次又一次地重复.有什么办法可以让这个视频结束后自动播放?
i am having an issue with playing back a video in my intro scene. i have added my video to the scene and it plays fine. i just want it to repeat again and again. is there any way to set this video to playback automatically 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];
感谢任何帮助.
推荐答案
使用以下方法初始化您的 SKVideoNode:
Initialize your SKVideoNode with:
- (instancetype)initWithAVPlayer:(AVPlayer *)player
设置AVPlayer时使用:
When setting up the AVPlayer use:
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[avPlayer currentItem]];
这将防止播放器在结束时暂停.
this will prevent the player to pause at the end.
在通知中:
-(void)playerItemDidReachEnd:(NSNotification *)notification {
AVPlayerItem *p = [notification object];
[p seekToTime:kCMTimeZero];
}
这将倒带电影.
这篇关于在 sprite kit 中永远播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文