play video forever in sprite kit

∥☆過路亽.° 提交于 2019-11-30 15:01:41
sangony

Initialize your SKVideoNode with:

- (instancetype)initWithAVPlayer:(AVPlayer *)player

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.

In the notification:

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

this will rewind the movie.

(Credit to Bastian for his answer to this question)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!