Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
3
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
Add comment · 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
5
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
Add comment · 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 $$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!

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 $$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

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.

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

load csv www 0 Answers

Trying to create a static class for WWW-based functions and such 0 Answers

Custom yield return 1 Answer


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