I'm trying to load and play a Video from a URL using the Unity VideoPlayer and everything works using this steeps.
Now I'm facing some troubles because I'm not able to access the clip properties throught my code, in fact when I use an URL to load a VideoClip the clip property in the VideoPlayer always return null.
I want this properties because I'm interested in the Width and Height of the video clip so I can resize them accord to my canvas or panel and it may vary depending on the video aspect ratio.
Because I'm using a RenderToTexture to display the video every time I ask for the Width and Height it returns the {w,h} of the RTT instead of the {w,h} of the video.
Is there a way to get arround this?
Thanks in advance.
I'm using Unity 2017.3.0f3
public string VideoPath = string.Empty;
public VideoPlayer player;
public delegate IEnumerator OnVideoReady();
public static event OnVideoReady VideoReady;
IEnumerator Start()
{
player = GetComponent<VideoPlayer>();
player.playOnAwake = false;
player.enabled = false;
yield return null;
// ABSOLUTE PATH TO THE VIDEO FILE
var path = UnifiedIO.SystemIO.Internal.Path.GetFullPath(VideoPath);
if(Debug.isDebugBuild)
{
Debug.Log("*** Path to 360 file : " + path);
}
// PREPARE ALL THE MEDIA DATA
player.source = VideoSource.Url;
player.url = path;
player.playOnAwake = true;
player.enabled = true;
player.Prepare();
yield return new WaitUntil(()=> player.isPrepared);
player.Play();
if(Debug.isDebugBuild)
{
Debug.LogFormat("*** Video Player information; aspect ratio {0}; frame {1}; frame count {2}, frame rate {3}," +
"playback speed {4}, source {5}, url {6}",
player.aspectRatio,
player.frame,
player.frameCount,
player.frameRate,
player.playbackSpeed,
player.source,
player.url);
Debug.LogFormat("*** Clip information; frame rate {0}, Width {1}, height {2}, lenght {3}, name {4}, " +
"original path {5}, pixel aspect ratio denominator {6}, pixel aspect ratio numerator {7}",
player.clip.frameRate,
player.clip.width,
player.clip.height,
player.clip.length,
player.clip.name,
player.clip.originalPath,
player.clip.pixelAspectRatioDenominator,
player.clip.pixelAspectRatioNumerator);
}
if (VideoReady != null)
StartCoroutine(VideoReady());
yield return new WaitForEndOfFrame();
if(FindObjectOfType<PanelFadeAnimation>())
FindObjectOfType<PanelFadeAnimation>().EnlightenScene();
}