如何获得VideoPlayer的源尺寸(宽度/高度)? [英] How can I get VideoPlayer source dimensions (width/height)?
问题描述
我正在使用Unity的新版(从〜5.6.x版本开始)视频播放器组件,以编程方式加载视频文件并进行播放.但是我希望能够检测源视频的尺寸,以便可以调整渲染纹理目标以及包含视频控制栏的GameObject的大小.
I'm using Unity's new (as of ~5.6.x) Video Player component to programmatically load a video file and play it. But I'd like to be able to detect the dimensions of the source video so that I can resize the render texture target as well as a GameObject containing a control bar for the video.
有什么方法可以访问这些属性?
Is there any way to access these properties?
目前,我可以看到有可能获得帧数等信息,这使我觉得我也应该能够获得视频的尺寸,但似乎看不到任何效果.
Currently, I can see it's possible to get the number of frames, etc, which makes me thing I should be able to get the video's dimensions as well, but nothing I can see seems to work.
推荐答案
您可以从 VideoPlayer
.然后可以从 VideoClip
中访问这些值.
You can get the video dimension such as the width and height from the VideoPlayer
. This can be done by retrieving the VideoClip
from the VideoPlayer
. Those values can then be accessed from the VideoClip
.
获取VideoPlayer
Get VideoPlayer
VideoPlayer vplayer = GetComponent<VideoPlayer>();
从VideoPlayer获取VideoPlayer剪辑
Get VideoPlayer clip from the VideoPlayer
VideoClip clip = vplayer.clip;
获取VideoPlayer的尺寸宽度/高度
Get VideoPlayer dimension width/height
float videoWidth = clip.width;
float videoHeight = clip.height;
您可能感兴趣的其他重要变量:
Other important variables you may be interested in:
double videoLength = clip.length;
float frameCount = clip.frameCount;
double frameRate = clip.frameRate;
如果您需要播放视频的帮助,可以查看此帖子.
If you need help playing video, you can check this post.
这篇关于如何获得VideoPlayer的源尺寸(宽度/高度)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!