How to Import .mp3 and use it as AudioClip

Hi all,

I need to let the user choose the .mp3 audio file to play at runtime (using a Dialog).

I’ve done a solution with WWW but it doesn’t support .mp3 (in my app I have no time to convert from ogg or wav to mp3s).

Works using NAudio but with that I’m losing all Audioclip’s properties (I absolutely need them).

What’s the best way to achieve this result?

Thank you

NAudio will allow you to get access to decompressed data, which you can then convert to floats and set in a clip.

I’m not familiar from NAudio, but a quick google yielded this mp3 to wav conversion example.

-Convert to wav
-Ditch the header, grab the data ( ints, most often int16
-Convert to float
-Create AudioClip of appropriate size, channels etc…
-Set data in clip

Much more elegant would be to stream small chunks to a looped AudioClip, would save lots of ram and having to write to disk first.

Hope it helps.