ios - 如何在 iOS Sprite Kit SKVideoNode 中控制视频的播放?

标签 ios sprite-kit

我将视频加载到我的 Sprite Kit SKVideoNode 中,但如何停止并重新开始播放或转到视频中的特定时间?我看到的只是播放和暂停方法。

// AVPlayer
NSURL *fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"HowToPlay" ofType:@"mp4"]];
_avPlayer = [AVPlayer playerWithURL:fileURL];

// SKVideoNode
_videoNode = [SKVideoNode videoNodeWithAVPlayer:_avPlayer];
[_videoNode play];

最佳答案

事实证明这对我有用。

重启:

[_videoNode removeFromParent];
 _videoNode = [SKVideoNode videoNodeWithVideoFileNamed:@"video.mp4"];
 _videoNode.position = ...
_videoNode.size = ...
[self addChild:_videoNode];
[_videoNode play];

暂停:

[_videoNode pause];
_videoNode.paused = YES;

播放:

[_videoNode play];
_videoNode.paused = NO;

关于ios - 如何在 iOS Sprite Kit SKVideoNode 中控制视频的播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27027648/

相关文章:

ios - 特定泛型类型参数的解决方法

iOS Sprite Kit - SKSpriteNode 似乎没有物理体参与模拟

swift - 为什么我的代码从未检测到与我的 SKPhysicsBody 有任何接触?

swift - SKSpriteNode 动画自下而上显示

ios - SpriteKit 移动到 X :duration from Current Stat

ios - Facebook 上针对 Unity SDK 6.0 的 FB.Init() 问题

ios - 在 Swift 3.0 中转换 base64String 中的音频文件

ios - 带有 Helvetica 的 SKLabelNode 产生滞后

ios - 按钮单击事件(UIButton TouchUpInside 操作)不起作用 - IOS/Swift

ios - Apple 反馈该应用程序在启动时崩溃