Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

assigning MovieTexture

Discussion in 'Editor & General Support' started by RifS, Dec 2, 2014.

  1. RifS

    RifS

    Joined:
    Nov 27, 2013
    Posts:
    33
    I'm trying to dynamically load a video from StreamingAssets folder, but somehow the www.movie returns a movie texture with duration -1

    Code (csharp):
    1.  
    2.     public    MovieTexture     movTex;
    3.     void Start ()
    4.     {
    5. #if UNITY_EDITOR
    6.         LoadIntroMovie();
    7. #else
    8.        // Play intro movie on Handheld device
    9. #endif
    10.     }
    11.  
    12. void LoadIntroMovie()
    13.     {
    14.         movTex = null;
    15.  
    16.         string videoFilePath = Application.streamingAssetsPath+"/Intro Videos/sample_mpeg4.mp4";
    17.         if (! System.IO.File.Exists(videoFilePath) )
    18.         {
    19.               Debug.LogError(videoFilePath + " does not exist!");
    20.               return;
    21.         }
    22.      
    23.         WWW www = new WWW( "file://" + videoFilePath );
    24.      
    25.         if (www != null)
    26.         {
    27.             while ( !www.isDone ) Debug.Log("Loading data " + www.url + "...");
    28.             Debug.Log(www.url + " loaded!");
    29.             movTex = www.movie;
    30.         }
    31.  
    32.         print("Movie texture duration : " + movTex.duration); // ERROR : Movie texture duration : -1
    33.  
    Any idea what went wrong?
    - The video file is definitely not corrupted. It's the sample .mp4 file I downloaded from Quick Time website and it plays OK if I simply drag and drop the file into the quad I use as a movie plane
    - The www loading method definitely work if I am about to fetch a text file (instead of movie)
     
    Last edited: Dec 8, 2014
  2. RifS

    RifS

    Joined:
    Nov 27, 2013
    Posts:
    33
    bump.

    Could anyone help me?