Search Unity

About WebGLMovieTexture with UI elements

Discussion in 'UGUI & TextMesh Pro' started by danidel3d, May 10, 2015.

  1. danidel3d

    danidel3d

    Joined:
    Jul 26, 2013
    Posts:
    10
    Hello @jonas echterhoff and the rest of this commUnity

    I'm using the plugin WebGLMovieTexture, (created by @jonas echterhoff is excellent, thank you.)

    But I need to know if is possible to use this in a UI element, like a Raw Image, simple Image, Panel, and how?

    bool jugo = false;

    WebGLMovieTexture m;
    void Start () {
    if (ApplicationModel.way == "0" && ApplicationModel.videostep == "0")
    {
    m = new WebGLMovieTexture("StreamingAssets/Draft_1.mp4");
    RawImage gt = GameObject.Find("videosToPlay").GetComponent<RawImage>();
    gt.texture = m​
    }​
    }

    void Update () {
    m.Update();
    if (m.isReady && !jugo)
    {
    m.Play();
    jugo = true;​
    }
    if (jugo)
    {
    //next
    if (m.time == m.duration)
    {
    ApplicationModel.videostep = "1";
    jugo = false;​
    }​
    }​
    }


    All that I can see is a black square.

    Can help me somebody?
     
  2. BabilinApps

    BabilinApps

    Joined:
    Dec 28, 2014
    Posts:
    40
    Yes just set the Material.mainTexture instead of the texture itself.
    Code (CSharp):
    1. GetComponent<RawImage>().material.mainTexture = tex;
    Happy Coding
     
  3. Anibal Hormeche

    Anibal Hormeche

    Joined:
    Jul 23, 2013
    Posts:
    4
    Hey! That didn't work for me (the video is not displayed)... I do listen to the video's audio, though. Notice that the example scene is working for me (rendering the video on a cube), it's only the RawImage the one that doesn't display anything.
     
  4. BabilinApps

    BabilinApps

    Joined:
    Dec 28, 2014
    Posts:
    40
    Can you repost your code, I'll happily take a look at it.
     
  5. Anibal Hormeche

    Anibal Hormeche

    Joined:
    Jul 23, 2013
    Posts:
    4
    Oh, nothing fancy: I just create the texture like this...

    Code (CSharp):
    1.  
    2. m_WebMovieTexture = new WebGLMovieTexture("StreamingAssets/" + m_MoviePaths[m_CurrentVideoIndex]);
    3. m_Image.material.mainTexture = m_WebMovieTexture;
    4.  
    And then I check if the texture is ready to play in an Update:

    Code (CSharp):
    1.  
    2. if (!m_PlaybackStarted && m_WebMovieTexture.isReady)
    3. {
    4.      m_WebMovieTexture.Play();
    5.      m_PlaybackStarted = true;
    6. }
    7.  
    When running in the web browser, I hear the video's audio track, but don't see anything on the RawImage (except the color I've already set on it).

    EDIT: I've tried using "m_Image.texture" before, but that didn't work (it did work with the standard MovieTexture, of course)
     
  6. Rissatto

    Rissatto

    Joined:
    Mar 16, 2013
    Posts:
    5
  7. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    I can get mine to play, but if i change to another video URL, it keeps streaming the old video, so now i have two internet streams.

    Anybody knows how to delete and remove an instance of the WebGLMovieTexture, or to make it start playing from a different URL?

    Seems its impossible to delete it and make a new one to play a different video, and the API only creates new ones if you want to play a different video, so the old ones are still sitting in memory streaming video from the internet.