我用AVPlayer实例初始化了一个SKVideoNode,当我调用AVPlayer's play方法时,视频不能播放。但是当我调用SKVideoNode实例的play方法时,它可以播放。
我必须使用AVPlayer而不是SKVideoNode的原因是我必须监控当前视频的currentTime,播放结束状态通知。但是SKVideoNode没有这两个属性状态。
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发布于 2015-08-18 08:40:59
同时使用SKVideoNode和AVPlayer来提供更细粒度的回放控制并没有错。我假设你正在使用SKVideoNode,因为正在使用SpriteKit,如果你需要的不仅仅是播放和暂停,你也会想要一个AVPlayer。
请注意,即使使用AVPlayer,您仍然会在SKVideoNode上调用play和pause。
https://stackoverflow.com/questions/31646201
复制相似问题