问题
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