- Home /
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
Assets doesn't fit my needs...my user has to choose between any of his .mp3 on his hard drive.
Answer by gregzo · Aug 07, 2013 at 09:17 AM
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.
I've tried using the $$anonymous$$p3ToWav(string mp3File, string outputFile) function in my scripts and passing it hard path but it doesn't seem to convert anything.
Anyway thank you for your support
Your answer
Follow this Question
Related Questions
Unspecified Error during Audio Import 0 Answers
Loading Audio Files at Runtime for Playback and Processing 1 Answer
Play MPEG from web options 0 Answers
Android play mp3 file 0 Answers