Accessing dimensions (width/height) from a VideoPlayer source URL

前端 未结 1 2030
[愿得一人]
[愿得一人] 2021-01-21 03:22

I am working on a Unity project that requires me to download a video file (mp4 format) and play it using the VideoPlayer component. Because the file is downloaded at runtime, I

相关标签:
1条回答
  • 2021-01-21 04:16

    You can retrieve these information from the Texture that VideoPlayer constructs.

    Get VideoPlayer

    VideoPlayer videoPlayer = GetComponent<VideoPlayer>();
    

    Get the Texture VideoPlayer

    Texture vidTex = videoPlayer.texture;
    

    Get VideoPlayer dimension width/height

    float videoWidth = vidTex.width;
    float videoHeight = vidTex.height;
    

    Make sure to only get the texture after videoPlayer.isPrepared is true. See my other answer for full code on how to play video make it display on RawImage component.

    0 讨论(0)
提交回复
热议问题