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
2
Question by dave_mm0 · Feb 18, 2013 at 07:21 PM · wwwruntimedynamic loading

Loading and playing AudioClip at runtime

Hello, I want the user to select a music file from his computer and play it in the game. Once I have the file path, I am unable to get the file to play. Here is what I have tried:

 function Start () {
     StartMusic();
 }
 
 function StartMusic() : IEnumerable{
     var importedClip : AudioClip;
     var pathUrl : WWW = new WWW("file://C:/1.ogg");
     importedClip = pathUrl.GetAudioClip(false);
     while(!importedClip.isReadyToPlay){
         yield pathUrl;
     }
     audio.clip = importedClip;
     audio.Play();
 }

I tried both wav and ogg files (mp3 is not supported). I don't get any error messages, but the music never starts! Is there anything I should/should not be doing here? thx!

Edit: I have tried with an imported audio clip and it works just fine, the problem seems to be with the usage of WWW.

Comment
Add comment · Show 3
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 barinelg · Feb 18, 2013 at 09:58 PM 1
Share

Have you tried an audio clip that was imported to see if it'll play? That will help deter$$anonymous$$e whether it's an import issue, an issue with the AudioSource, or a general logic issue.

avatar image dubbreak · Feb 18, 2013 at 11:26 PM 0
Share

Have you tried putting some break points in and debugging? Does it ever get past the loop waiting on isReadyToPlay? If it does get past there what's importedClip looks like if you inspect it? Do the values in its fields make sense?

avatar image Professor Snake · Feb 18, 2013 at 11:52 PM 0
Share

By the way, Unity can only use .ogg files. EDIT: Perhaps it gets played but you can't hear it. Try changing pathUrl.GetAudioClip(true); to pathUrl.GetAudioClip(false);

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by dave_mm0 · Apr 25, 2013 at 02:16 PM

So, since you can't stream mp3s with WWW on a Desktop (only on mobile) and on iOS you can't access mp3s with WWW because of the sandbox... I ended up reading the MP3 (native iOS, Android code with Unity plugin, and MP3Sharp on Desktop) and using the PCMCallBack on the SoundClip to import at runtime.

Comment
Add comment · Show 10 · 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 murkantilism · Jan 12, 2014 at 10:18 PM 0
Share

What plug-in did you use for Android?

Can you detail how you were able to successfully import and play an $$anonymous$$P3 file across all 3 platforms?

avatar image dave_mm0 · Jan 14, 2014 at 08:01 PM 0
Share

For Android & PC: I am reading the PC$$anonymous$$ data using F$$anonymous$$od and strea$$anonymous$$g it to Unity3d. I wrote the plugin to do this myself. For iOS: I am reading the PC$$anonymous$$ data using the AV$$anonymous$$ediaFoundation framework, and strea$$anonymous$$g the data to Unity in the same way

avatar image murkantilism · Jan 16, 2014 at 02:21 AM 0
Share

Thank you very much for the reply dave!

Forgive my ignorance, I'm quite experienced with Unity but very new to working with $$anonymous$$P3 files:

What is PC$$anonymous$$ data? Is your homebrew plug-in available somewhere like GitHub where read through it?

I looked at F$$anonymous$$od and AV$$anonymous$$ediaFoundation - did you use a commercial license for F$$anonymous$$od?

Thanks for your time dave!

avatar image dave_mm0 · Jan 16, 2014 at 03:10 AM 0
Share

PC$$anonymous$$ Data is the raw audio data you get after uncompressing an $$anonymous$$P3 file, it stands for Pulse-code modulation. You can use Unitys AudioClip.Create and ask your plugin for the data in the PC$$anonymous$$ReaderCallback function, and copy the PC$$anonymous$$ data into your audioclip. $$anonymous$$y plugin is not available, since I made it for a commercial game which should come out soon :) I did use a commercial license of F$$anonymous$$od, but since Unity already comes with F$$anonymous$$od, if you contact the nice people there, you can work out a deal to use it for cheap.

avatar image murkantilism · Jan 16, 2014 at 05:46 AM 0
Share

Thanks very much dave, I appreciate the replies! That cleared a lot up for me. Thanks for the tip too! Unfortunately I'm a 4th year college student and can't afford to get the Unity Pro license to use plug-ins (or pay F$$anonymous$$od). I think I'll just implement a complete solution for iOS/Droid with WWW and a gimped one for PC.

Show more comments
avatar image
0

Answer by aeroson · Aug 18, 2015 at 06:08 PM

Just released asset that allows you to load AudioClip from waw, mp3, aiff and ogg files at runtime: http://u3d.as/content/neitri-industries/runtime-audio-clip-loader

Comment
Add comment · 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

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

14 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

Related Questions

Finding size of images imported at runtime 2 Answers

php WWW not working in unity web player 1 Answer

www faster than Resources.Load? 0 Answers

Load object at runtime using webplayer 0 Answers

@ makes problem in ios 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