- Home /
Speed of WWW
I was using something like this to load a dynamically created audio file on ios.
WWW AudioToLoadPath = new WWW("file://" + Application.persistentDataPath+"/audio.wav");
Camera.main.audio.clip = AudioToLoadPath.audioClip;
Camera.main.audio.Play();
However, there seems to be a noticeable delay from the time that the audio file is created to the time when it is played. The audio file is created very quickly so I know that is not the problem. I think the issue must be with WWW. Is WWW very slow and if so, is there a faster way to load the file?
Is the audio file set to decompress or play in a streamed fashion?
Do you mean the setting Load Type is on or something else?
Yeah that is what I was thinking - but on reflection that probably isn't possible on just a file being loaded by WWW. Not sure but was thinking that this might have a delay while it was prepared.
I could see if I can change the file's import settings to see if WWW loads faster. Not sure if it makes a difference though.
Answer by Dreamora · Sep 18, 2012 at 09:52 PM
You can alter the thread priority of the WWW object.
But likely the only way to approach your problem is a pro license and asset bundles so you can control compression settings and when / how its meant to be decompressed etc
I have a pro license but I thought asset bundles have to be created beforehand in order to work (correct me if I am wrong). I have only one audio file being created and loaded but the information in the file is being changed via script so the audio file is overwritten whenever a change occurs (it changes a lot). Therefore, I would run my above code whenever a change occurs. Creating the file is a really quick process but there is considerable lag when I try to look for the new file on the device and play it.
That is correct, it needs to be editor generated. But you could host a headless editor that generates it for you.
though if it changes a lot you will basically not be able to avoid the hit from using it directly but you can 'overcome' it by loading the audio already beforehand and store the audioclip in a global manager to use it once its required (and after its loaded) as the problem is the www.audio access at which point the byte data is converted into actual audio data and prepared for usage
While the audio does exist on the device, it $$anonymous$$UST be reloaded by WWW every time a change occurs which is extremely often. Unless I am misunderstanding you, there is no way to load it beforehand because it is almost always changing and reloading (Audio is created via c# script and its contents change based on settings changed in unity). Unless what you meant is make an audio file beforehand and copy the data from my audio file to the one already created?
Doing the WWW call and assigning www.audio to a audioclip reference and after that send out notifications 'on it being updated' is 'loading it beforehand' actually and would be the way to go if you do want unity to handle it for you, loading it from a web location, ...
You naturally also can use SetData on the AudioClip class ( http://docs.unity3d.com/Documentation/ScriptReference/AudioClip.html ) but to what degree thats gonna make you happy or even do what you want is a thing you will have to find out.
I tried something like that before but it ended with the same noticeable lag on the iphone. I should also note that the audio is only about 1-2 milliseconds long and the creation and playing of the audio happens in a coroutine.
WWW AudioToLoadPath = new WWW("file://" + Application.persistentDataPath+"/audio.wav"); yield return AudioToLoadPath; AudioClip TestClip = AudioToLoadPath.GetAudioClip(false); Camera.main.audio.clip = TestClip; Camera.main.audio.Play();