- Home /
www AudioClip returning incorrect length
I am getting a .ogg file from a www. When i poll clip.length it is returning 48695.77 seconds. If I drag that same file into the editor, the length is displayed at 0.821 seconds.
// ...loading a local Audio file with an www.
var www : WWW = new WWW("file://C:\Users\...\voc_01.ogg");
yield www;
var clip : AudioClip = www.GetAudioClip(true,true);
if (clip != null)
{
Debug.Log("SoundLength = " + clip.length);
}
why is clip.length spitting out such a huge number? What am I doing wrong here?
bump. having the same issue with streamed OGG files. interestingly enough, i get the exact same clip.length (48695.77) despite my OGG file being 2'39" long. unity bug?
BU$$anonymous$$P: I'm observing this issue in 4.1.2f1.
Answer by mleblanc · Jul 05, 2013 at 07:39 PM
You can't get the lenght of a streaming audioclip. You need to wait for all the data to be loaded.
Try that: www.GetAudioClip(true, false);
(if you can non-streaming audio)
O$$anonymous$$ but what do you do when you actually want to stream? Is there no solution for that in Unity currently? I guess you could try to pull down the file in the background just to get the length then chuck it, while strea$$anonymous$$g the actual WWW, but that seems excessive and sloppy.
For now, it's seem impossible to stream with WWW and have a lenght or to find when the clip end. I'll fill a bug.
$$anonymous$$y "fix/hack" for now, it's to read the header of the ogg to get the duration...
I use that: http://oggvorbisdecoder.codeplex.com/
Your answer
Follow this Question
Related Questions
WWW GetAudioClip not working correctly for Unity 4? 1 Answer
How to have www streaming to work with a radio station? 1 Answer
loading/streaming audioclip using www class [android] 0 Answers
How do i stream music from a server? 0 Answers
How to avoid lag when using WWW class to download sound 3 Answers