Hello,
As the title says, while I have successfully used the VideoPlayer to display a video in a RawTexture, I can’t get it to work in my build, in Unity 5.6.1f1.
Here is how I use it:
private string texLocation;
private VideoPlayer videoPlayer;
private string message = " ";
IEnumerator PlayVideo()
{
videoPlayer.Play();
Debug.Log("Playing"+message);
while (videoPlayer.isPlaying)
{
Flux.texture = videoPlayer.texture;
yield return null;
}
}
private IEnumerator PrepareVideo()
{
//Wait until video is prepared
WaitForSeconds waitTime = new WaitForSeconds(5);
while (!videoPlayer.isPrepared)
{
Debug.Log("Preparing" + message);
//Prepare/Wait for 5 sceonds only
yield return waitTime;
//Break out of the while loop after 5 seconds wait
break;
}
}
void Start() {
if (IsInLocalConfig(assigned)) // this is an unrelated part of the code, but it does get accessed
{
isLocalVideo = true;
texLocation = Application.streamingAssetsPath + "/" + LocalCameraManager.Instance.localCameras.data.FirstOrDefault(i => i.guid == assigned.Guid).videoLocation;
videoPlayer = Flux.gameObject.AddComponent<VideoPlayer>();
videoPlayer.source = VideoSource.Url;
videoPlayer.playOnAwake = true;
videoPlayer.renderMode = VideoRenderMode.RenderTexture;
videoPlayer.url = texLocation;
videoPlayer.isLooping = true;
videoPlayer.errorReceived += (source, err) => { message += "{error:" + err + "} "; };
videoPlayer.prepareCompleted += (source) => { message += "{video is prepared} "; videoPlayer.Play(); };
videoPlayer.started += (source) => { message += "{video has started} "; };
message += videoPlayer.url;
Debug.Log("Init" + message);
}
}
public void OpenLive()
{
if (isLocalVideo)
{
StartCoroutine(PrepareVideo());
StartCoroutine(PlayVideo());
}
else... // also unrelated code
}
OpenLive() is called with a button. It does get called as I get the Log messages in the coroutines
but nothing is displayed. The “Init” log also appears, however, message seems to be empty in build, though it works fine in editor.
Is there something I am doing wrong?