videoPlayer.url = new Uri(path).AbsoluteUri;
videoPlayer.Prepare();
And when “prepareCompleted” is triggered I have a null value on “videoPlayer.clip” property. If I load a video from an url (in my case is a locale filesystem url) I suppose that VideoPlayer should fill that property with the info recovered from that url.
Because of that I can’t access to “clip.width”, “clip.height”, “clip.length”…
How can I dispose the video loaded from the VideoPlayer so I can reuse it later to load another video? I suppose that this it’s not the correct way:
UnityEngine.Object.Destroy(videoPlayer.texture);
Because there could be some other references and garbage left behind.
When setting the VideoPlayer’s url field, any pre-existing clip will be left intact so you can go back to it by simply changing the source. So relying on videoPlayer.clip.width is not a reliable way of getting at the width of what is currently being played.
However, when the preparation is completed (using the “prepared” event), see if you can use videoPlayer.texture.width. This should be a reliable way to get the information you need.
In the VideoPlayer class, the clip and url are separate fields and the fact that both can be set at the same time is already documented. But the UI-level documentation is not yet written; I’ll make sure this behaviour is pointed out, thanks for your input.
The VideoClip class has both a frameCount and a length field for this purpose.
The VideoPlayer class has a frameCount field. It will be the same as the clip if playing from a clip, or it will be that of the url if playing from a url. In this last case, it only becomes valid once the preparation is completed. You can test that the preparation is completed using the “isPrepared” property, or using the prepareCompleted event.
You don’t need to dispose of this texture: it is volatile and only present to let you inspect the texture during the player’s life scope.
By using videoPlayer.frameCount. As mentioned, this will be set as soon as the preparation is completed. This gives you a uniform way to get the duration of whatever is being played, clip or URL.
So if you were to prepare a string to display time/length, you would say (using a hypothetical MakeTimecode function that uses the frame rate to make a pretty display):
The preparation takes just a bit of time while the underlying playback engine fetches the initial stream chunks. While the preparation is ongoing, you can show --:-- / --:–, or some other content revealing that the stream is not yet ready for playback.