如何在iOS Sprite Kit SKVideoNode中控制视频的播放? [英] How do I control playback of a video in an iOS Sprite Kit SKVideoNode?

查看:434
本文介绍了如何在iOS Sprite Kit SKVideoNode中控制视频的播放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I load a video into my Sprite Kit SKVideoNode, but how do I stop and restart the playback or go to a specific time in the video? All I see are play and pause methods.

// 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 Sprite Kit SKVideoNode中控制视频的播放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆