Load external mp3 File without streaming

Hello,

I need to load external mp3 files and i don`t need to stream it.
Using WWW class:

// Use this for initialization
	void Start () {
		
		StartCoroutine(LoadMp3("file://C:/Users/Cristian/Music/Cera.mp3"));
		
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	IEnumerator LoadMp3(string url) {
	
		WWW m_get = new WWW(url);
		
		yield return m_get;
	
		GetComponent<AudioSource>().audio.clip = m_get.audioClip;
	
		audio.Play();
		
	}

But it returns this error message: “Streaming of ‘mp3’ on this platform is not supported”

Is there a way to wait the download of entire file and after play it?

Thanks!

A quick tip: yield return will wait until the entire file is downloaded/loaded into the game. I'm saying this because in your code you use yield return... while in your question you ask how to wait until the download is finished even though your code already does that!

1 Answer

1

Unity doesn’t support streaming (or) loading MP3 files on WebPlayer and windows standalone. However it supports on mobile platforms. As an alternative you can convert your mp3 file to .ogg format and I think you code will work as expected.

You can use AudaCity to convert mp3 to ogg.

Thanks for the answer! my target plataform will be only windows The idea is create a mini mp3 player, and convert all the user musics i think it will not be a good way, then i'm using winmm.dll to play mp3 files and it works great!

Can you elaborate more on how you are using winmm.dll. Please put some code blocks to help understand better. Thanks in advance

Thank you (A vote-up for this). I will try to use this for sure. BTW, multiple mp3 files can be played using this simultaneously ?

I never tried but i saw references that said it is possible, you just need to "Open" two mp3 files and call "Play" for them, don't forget to create a different alias for each file

I would like my project to support multiple music file types. Is there a way to test this feature on Unity, or i'll just have to create an apk file and test it myself on my phone?