Search Unity

Video Unable to set VideoPlayer URL at runtime

Discussion in 'Audio & Video' started by JulienNesme, May 11, 2020.

  1. JulienNesme

    JulienNesme

    Joined:
    Sep 21, 2019
    Posts:
    1
    I'm trying to add runtime VideoPlayer in Unity 2020.1.0b5 and cannot set the url.

    Code (CSharp):
    1. VideoPlayer vp = video_player.AddComponent<VideoPlayer>();
    2.    vp.source = VideoSource.Url;
    3.    vp.playOnAwake = false;
    4.    vp.renderMode = UnityEngine.Video.VideoRenderMode.MaterialOverride;
    5.    vp.targetMaterialRenderer = GetComponent<Renderer>();
    6.    vp.targetMaterialProperty = "_MainTex";
    7.    vp.url = trackedGOConf.video_url;
    8.    vp.isLooping = true;
    9.    vp.Play();
    10.  
    11.    Debug.Log("URL:" + vp.url + ":" + trackedGOConf.video_url + ":");
    The debug line indicates that vp.url is still empty, whereas trackedGOConf.video_url contains the right url. I tried many different ways, like instantiating a prefab with a preset url. Then this preseted url cannot be replaced. Is this something belonging to this version of Unity being a beta ? Or did I do something wrong ? Thank you in advance for your help.
     
  2. DominiqueLrx

    DominiqueLrx

    Unity Technologies

    Joined:
    Dec 14, 2016
    Posts:
    260
    Hi Julien!

    I just tried your scenario over here and it does work for me. I adjusted your script in 2 ways:
    • Add a VideoPlayer onto the current game object
    • Have a URL known to work, and I've set this script onto a sphere object.

    VideoPlayer vp = gameObject.AddComponent<VideoPlayer>();
    vp.source = VideoSource.Url;
    vp.playOnAwake = false;
    vp.renderMode = UnityEngine.Video.VideoRenderMode.MaterialOverride;
    vp.targetMaterialRenderer = GetComponent<Renderer>();
    vp.targetMaterialProperty = "_MainTex";
    vp.url = "http://docs.evostream.com/sample_content/assets/bun33s.mp4";
    vp.isLooping = true;
    vp.Play();
    Debug.Log("URL:" + vp.url);


    One possibility is that your URL points to a format that is not supported by the VideoPlayer, in which case the URL will indeed not be kept. This is by design and you'd normally get an error message in the console when in the editor, as well as a callback on the VideoPlayer.errorReceived event (both in editor and runtime).

    Can you tell us what the URL is?

    Dominique