2
votes

I init a SKVideoNode with an AVPlayer instance, When I call AVPlayer's play method, the video don't play. But It can play when I call SKVideoNode instance's play method.

The reason I have to use AVPlayer not SKVideoNode is that I have to monitor the current video's currentTime, play ended status notification. but SKVideoNode doesn't have these two property status.

self.player = [[AVPlayer alloc] initWithURL:url];
self.videoNode = [SKVideoNode videoNodeWithAVPlayer:self.player];
//some other code are not related to this, so I omit them here

//These two observe can work
[self.player.currentItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying) name:AVPlayerItemDidPlayToEndTimeNotification object:self.player.currentItem];

//[self.player play]; This method doesn't make video play
[self.videoNode play];//This one does
1

1 Answers

-1
votes

There is nothing wrong with using both an SKVideoNode and an AVPlayer together to provide more fine grained control over playback. I am assuming you are using the SKVideoNode because SpriteKit is being used, if you need anything beyond just play and pause you will also want an AVPlayer.

Just note that even with the AVPlayer you are still calling play and pause on the SKVideoNode.