Search Unity

MovieTexture.Duration is -1

Discussion in 'Editor & General Support' started by Rudy-Pangestu, Sep 22, 2014.

  1. Rudy-Pangestu

    Rudy-Pangestu

    Joined:
    May 24, 2013
    Posts:
    16
    Hi Unity Support Team,

    I'm trying to load .ogv file as a MovieTexture.

    Everything is fine, until I find that some .ogv files Duration is always -1. Depending on the file, sometimes the Duration is loaded correctly. I have put the Duration inside Update() function and even until the movie is finished playing, it's still -1.

    Sample .ogv file that the duration is always -1: https://s3.amazonaws.com/labsterim/media/videos/small.ogv

    Another file that the duration is correct: http://unity3d.com/files/docs/sample.ogg

    Any idea why this is happening? Is it because the movie encoding settings is different or something? Any help is greatly appreciated. Thanks!

    Edit:
    I am using Unity 4.5.2f1.
     
  2. John Fallon

    John Fallon

    Unity Technologies

    Joined:
    Jul 1, 2014
    Posts:
    44
    I will look into this. What exactly are you trying to achieve with MovieTexture.duration? Generally MovieTexture.isPlaying is sufficient.
     
  3. Rudy-Pangestu

    Rudy-Pangestu

    Joined:
    May 24, 2013
    Posts:
    16
    I'm trying to create a simple video player in Unity. I need the duration to displayed at the corner, together with current playback time (which I calculate it myself).
     
  4. Rudy-Pangestu

    Rudy-Pangestu

    Joined:
    May 24, 2013
    Posts:
    16
    No answer yet? :(
     
  5. John Fallon

    John Fallon

    Unity Technologies

    Joined:
    Jul 1, 2014
    Posts:
    44
    This appears to be a bug.

    Edit:
    C̶o̶u̶l̶d̶ ̶y̶o̶u̶ ̶s̶u̶b̶m̶i̶t̶ ̶a̶ ̶b̶u̶g̶ ̶r̶e̶p̶o̶r̶t̶ ̶a̶n̶d̶ ̶w̶r̶i̶t̶e̶ ̶t̶h̶e̶ ̶c̶a̶s̶e̶ ̶n̶u̶m̶b̶e̶r̶ ̶i̶n̶ ̶t̶h̶i̶s̶ ̶t̶h̶r̶e̶a̶d̶?̶

    I am working on a fix for this. I will post in this thread again when I have an update for you.
     
    Last edited: Oct 2, 2014
  6. Rudy-Pangestu

    Rudy-Pangestu

    Joined:
    May 24, 2013
    Posts:
    16
    Thanks, I'll be waiting
     
  7. John Fallon

    John Fallon

    Unity Technologies

    Joined:
    Jul 1, 2014
    Posts:
    44
    I have implemented this fix and it should be available in next week's patch release.
     
    Josh-Naylor likes this.
  8. H-Fly

    H-Fly

    Joined:
    Sep 8, 2013
    Posts:
    4
    :)
     
  9. H-Fly

    H-Fly

    Joined:
    Sep 8, 2013
    Posts:
    4
    win7 4.5.5 f1 not OK
     
  10. John Fallon

    John Fallon

    Unity Technologies

    Joined:
    Jul 1, 2014
    Posts:
    44
    No, it'll be in 4.5.5 Patch 1 (release date: 16th October 2014).
     
    Last edited: Oct 16, 2014
  11. John Fallon

    John Fallon

    Unity Technologies

    Joined:
    Jul 1, 2014
    Posts:
    44
  12. H-Fly

    H-Fly

    Joined:
    Sep 8, 2013
    Posts:
    4
    John Fallon likes this.
  13. Rudy-Pangestu

    Rudy-Pangestu

    Joined:
    May 24, 2013
    Posts:
    16
    Hi John,

    I have downloaded Unity 4.5.5p1. It's still the same as before, the duration is -1 :-(
     
  14. John Fallon

    John Fallon

    Unity Technologies

    Joined:
    Jul 1, 2014
    Posts:
    44
    Hmm, interesting. With the fix, my test project is successfully returning the duration of the sample .ogv file in the link you provided. It appears to have worked for other users too. Could you submit a bug report ("Help" -> "Report a Bug") with a reproducible project and then write the case number in this thread? This will allow me to see the problem and under what circumstances it arises.
     
    Last edited: Oct 17, 2014
  15. Rudy-Pangestu

    Rudy-Pangestu

    Joined:
    May 24, 2013
    Posts:
    16
    Sorry, false alarm. I've just tried it again and it works now. I must be opening the wrong version of unity back then.

    Thanks a lot!
     
    H-Fly and John Fallon like this.
  16. Rudy-Pangestu

    Rudy-Pangestu

    Joined:
    May 24, 2013
    Posts:
    16
    Hi again John,

    Sorry, it seems like the behaviour is totally random. Now the duration is back to -1 again. Sometimes when I debug it, the duration is correct. But mostly it is -1.

    I have attached a sample script here. Can you please try it and confirm back to me?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TestMovieTexture : MonoBehaviour
    5. {
    6.     WWW www;
    7.     // Use this for initialization
    8.     void Start ()
    9.     {
    10.         StartCoroutine(Foo());
    11.     }
    12.  
    13.     IEnumerator Foo()
    14.     {
    15.         www = new WWW("https://s3.amazonaws.com/labsterim/media/videos/small.ogv");
    16.         while (!www.isDone)
    17.         {
    18.             yield return null;
    19.         }
    20.  
    21.         Debug.Log(www.movie.duration);
    22.     }
    23.    
    24.     // Update is called once per frame
    25.     void Update ()
    26.     {
    27.         Debug.Log(www.movie.duration);
    28.     }
    29. }
     
  17. John Fallon

    John Fallon

    Unity Technologies

    Joined:
    Jul 1, 2014
    Posts:
    44
    Yeah, there seems to be a problem with the WWW class. This will have to be looked into. If you have Unity Pro however, some slight modifications to your code using MovieTexture can fix the problem.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TestMovieTexture : MonoBehaviour
    5. {
    6.     WWW www;
    7.     private float duration;
    8.  
    9.     // Use this for initialization
    10.     void Start ()
    11.     {
    12.         StartCoroutine(Foo());
    13.     }
    14.    
    15.     IEnumerator Foo()
    16.     {
    17.         www = new WWW("https://s3.amazonaws.com/labsterim/media/videos/small.ogv");
    18.  
    19.         var movieTexture = www.movie;
    20.         while (!movieTexture.isReadyToPlay)
    21.             yield return null;
    22.  
    23.         duration = movieTexture.duration;
    24.     }
    25.    
    26.     // Update is called once per frame
    27.     void Update ()
    28.     {
    29.         Debug.Log(duration);
    30.     }
    31. }
    32.  
     
    Graham-Dunnett likes this.
  18. Rudy-Pangestu

    Rudy-Pangestu

    Joined:
    May 24, 2013
    Posts:
    16
    Yup, I have Unity Pro license.

    Ahh okay, I think I see the cause now. I have to store www.movie into a separate variable. I can't directly use www.movie to access the duration later on. It seems like the reference to www.movie is disposed or something. This is kinda weird, but at least now I know how to solve it.

    I have tested it in my main project. Yes, the duration is correct now.
    Thanks for the help!
     
    John Fallon likes this.