play video forever in sprite kit

前端 未结 1 1300
失恋的感觉
失恋的感觉 2021-01-03 02:10

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 an

相关标签:
1条回答
  • 2021-01-03 03:02

    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)

    0 讨论(0)
提交回复
热议问题