2

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
4

1 回答 1

-1

SKVideoNode同时使用 an和 anAVPlayer来提供对播放的更细粒度的控制并没有错。我假设您使用的是SKVideoNode因为SpriteKit正在使用,如果您需要的不仅仅是播放和暂停,您还需要一个AVPlayer。

请注意,即使使用 ,AVPlayer您仍在调用 play 并在SKVideoNode.

于 2015-08-18T00:40:58.853 回答