I have a big problem with my project Unity!
Indeed, I need to read many musics (for a blindtest) and thus I would like to pass by a server to upload my musics (to avoid having an application weighing several Go).
I use the class WWW which works, but every music puts at least 30 seconds/1 minute before playing… How to have the music immediatly?
Furthermore, I would like to use as URL a “compartment” of a array wich contain all the links. But impossible to do it because I have an error message.
Here is the code which I use :
IEnumerator loadMusic()
{
string[] Col = BlindTest[2].Split(',');
string url = Col[5];
GameObject Musique = GameObject.Find("Musique");
AudioSource audioSource = Musique.GetComponent<AudioSource>();
WWW music = new WWW(url);
yield return music;
AudioClip lamusic = music.GetAudioClipCompressed(true, AudioType.MPEG);
audioSource.clip = lamusic;
audioSource.Play();
}
you are downloading the whole audio file prior to playing - that’s why it always take long before playback begins
use streaming flag for getting the audio clip:
I’m not sure what you mean by compartment, but you can define a list of urls to be accessible in inspector, fill the values there, and then iterate on the list as needed:
public class Loader: MonoBehaviour
{
public List<string> urls;
...
public void PlayMusic(int i)
{
StarCoroutine(this.PlayMusicWithUrl(this.urls[i]));
}
...
}
For the both methods, there is the same problem… There is no probleme to play a file from my PC; but to play a song upload on a server, there is a lot of latency before the song is played…
@EddieRATIGNIER I’ve just tried a 65 MB oggvorbis file hosted on VPS, and with music.GetAudioClipCompressed I got roughly 1m 40s until playback started, with music.GetAudioClip cca 1m 4s
/ Unity 5.5.3f1 winx64 /
I definitely expected the latter to be much (much) quicker, so there’s definitely something not right.
At the moment I can only recommend my plugin (link in the signature… ) where the playback started under 2 seconds.
Discovered one caveat with AudioStream though: the dropbox links do not seem to work - presumably due to how dropbox handles secure links redirection, which was changed over time :-[
It certainly does not look like it, things to try :
try actual standalone / mobile build of the application, editor results might not be accurate ( although I doubt the result will be better / )
try different Unity versions - presumably even around 4.7
new UnityWebRequest does not have yet audio streaming handler implemented last time I checked
this is worth filing a bugrepot
if you don’t want to spend money you can download and use the FMOD Unity plugin yourself ( my package just uses it in a nice way for user, and provides integration with AudioSource )
there are few other audio solutions e.g. from wwise, or even NAudio for .net which are worth checking out and might help
You know if in previous version of Unity, the streaming (WWW.GetAudioClip) work without latency?
And you can help me to find a solution? Because i’m beginner and it’s very difficult for me to find another way… especially when there is no tutorial on the Internet…
@EddieRATIGNIER I’ve used stream links of internet radios intensively around 4.1-4.4 I think and those worked, I’m not 100% sure about hosted files;
But it’s easy to find out: the code would be the same as what you have now, just use GetAudioClip with streaming flag
If you encounter any problem just post here
I might be able to try it out later with 4.7 and 5.3
Looks like streaming of hosted files using GetAudioClip is/was broken all along:
4.7
dropbox ~ 13 sec
VPS more than 3 min
5.3
dropbox ~ 13 sec
VPS ~ 3:00 min
5.5
dropbox ~ 13 sec
VPS 2 - 3 min
From the above it looks like the whole file is downloaded in full each time even with stream flag set ( dropbox gets full bandwidth, my crappy VPS does some things to limit it )
On the behalf of the internet I would like to apologize for the incorrect advice stated in my first reply @EddieRATIGNIER
At this point there are not good AssetStore free options, esp. since you are new to unity - plugging separate network audio stream into AudioSource is little bit more involved;
I have used below plugins for streaming audios on iOS and Android and they work out of the box. Developer is also very helpful. Provided support when ever was required.