How can I get VideoPlayer source dimensions (width/height)?

霸气de小男生 提交于 2019-12-12 05:29:00

问题


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.


回答1:


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.

Get VideoPlayer

VideoPlayer vplayer = GetComponent<VideoPlayer>();

Get VideoPlayer clip from the VideoPlayer

VideoClip clip = vplayer.clip;

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.



来源:https://stackoverflow.com/questions/45290054/how-can-i-get-videoplayer-source-dimensions-width-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!