- Home /
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!
Answer by appearance · Mar 23, 2013 at 08:53 AM
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 $$anonymous$$i 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
Sure, I created a $$anonymous$$usicPlayer class:
public class $$anonymous$$usicPlayer
{
private string Pcommand;
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand,StringBuilder strReturn, int iReturnLength, int bla);
/// Stops currently playing audio file
public void Close()
{
Pcommand = "close $$anonymous$$ediaFile";
mciSendString(Pcommand, null, 0, 0);
}
/// Opens audio file to play
public void Open(string sFileName)
{
Pcommand = "open \"" + sFileName + "\" type mpegvideo alias $$anonymous$$ediaFile";
mciSendString(Pcommand, null, 0, 0);
}
/// Plays selected audio file
public void Play()
{
Pcommand = "play $$anonymous$$ediaFile";
mciSendString(Pcommand, null, 0, 0);
}
}
And here are some references that i used: http://msdn.microsoft.com/pt-br/library/windows/desktop/dd757161(v=vs.85).aspx http://www.codeproject.com/Articles/16316/Audio-Player-using-winmm-dll-and-WPL-File
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
Your answer
Follow this Question
Related Questions
Load mp3 from Harddrive on PC (again) 1 Answer
www-Class for loading local texture is very slow 2 Answers
load csv www 0 Answers
Trying to create a static class for WWW-based functions and such 0 Answers
Custom yield return 1 Answer