• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by CristianKhalil · Feb 26, 2013 at 02:29 PM · wwwloadyieldexternalmp3

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!

Comment
cowlinator
vexe
gregroberts

People who like this

3 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image phxvyper · Oct 03, 2013 at 06:00 AM 0
Share

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 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

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.

Comment
qwertyk31
vexe
skullthug
Bunny83
arufolo

People who like this

5 Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CristianKhalil · Mar 25, 2013 at 02:15 PM 0
Share

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!

avatar image appearance · Mar 26, 2013 at 06:38 AM 0
Share

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

avatar image CristianKhalil · Mar 26, 2013 at 02:49 PM 5
Share

Sure, I created a MusicPlayer class:

 public class MusicPlayer
     {
         
         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 MediaFile";
             mciSendString(Pcommand, null, 0, 0);
             
         }
         
         /// Opens audio file to play
         public void Open(string sFileName)
         {
             Pcommand = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
             mciSendString(Pcommand, null, 0, 0);
         }
         
         /// Plays selected audio file
         public void Play()
         {
             Pcommand = "play MediaFile";
             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

avatar image yoyyoffg CristianKhalil · Jul 12, 2017 at 10:31 AM 0
Share

Thanks ! It works like a charm

avatar image appearance · Mar 27, 2013 at 12:31 PM 0
Share

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 ?

avatar image CristianKhalil · Mar 27, 2013 at 08:11 PM 0
Share

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

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Load mp3 from Harddrive on PC (again) 1 Answer

www-Class for loading local texture is very slow 2 Answers

WebPlayer and WWW, stalls forever on get.... 0 Answers

How to imitate yield functionality like WWW class 0 Answers

WWW.getAudioClip() returning wrong length from one server but not another 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges