Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 fluxhackspro · Jun 15, 2018 at 05:00 PM · wwwloadaudioclip

Load audioclip from folder on computer into game, in runtime

Hello I want the player to specify the music in the game, and for that i need to load it somehow from a folder on the computer. Specificly i want to load all audioclips of mp3 from a specific folder. Probably the same as the game folder, then import them into the game somehow. I've been researching a bit and found this: https://docs.unity3d.com/ScriptReference/WWW.GetAudioClip.html

But how does one use this correctly and actually set some kind of prefix to the correct folder?

UPDATE:

Unity doesn't support mp3 it looks like so i converted to .wav I found a post on unity forums and here is my code. Note that his still doesnt give me anything, i dont get an error but the debug message is empty so it doesnt find the file correctly?

Any help is welcome

     public AudioClip[] clips;
     private string musicDir = "C://Users//Ägaren//Documents//FluxClips";
     AudioSource source;
 
     void Awake ()
     {
         source = GetComponent<AudioSource> ();
     }
 
     void Start ()
     {
         //AudioClip selectedClip = clips [Random.Range (0, clips.Length)];
         WWW audioLoader = new WWW ("file://" + musicDir + "//clip.wav");
         AudioClip selectedClip = audioLoader.GetAudioClip (false, false, AudioType.WAV);
         source.clip = selectedClip;
         Debug.Log (source.clip.name);
     }
Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by neoRiley · Mar 13, 2020 at 04:52 PM

@fluxhackspro - thanks for the reminder on how to load from the file system - I thought I'd throw this out as a possible answer as well with the updated UnityWebRequest/UnityWebRequestMultimedia object with an async example:

 async void Start()
 {
     // build your absolute path
     var path = Path.Combine(Application.dataPath, "Audio", "sounds", "myAudioClip.wav");
     
     // wait for the load and set your property
     CurrentClip = await LoadClip(path);
 
     //... do something with it
 }
 
 async Task<AudioClip> LoadClip(string path)
 {
     AudioClip clip = null;
     using (UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(path, AudioType.WAV))
     {
         uwr.SendWebRequest();
 
         // wrap tasks in try/catch, otherwise it'll fail silently
         try
         {
             while (!uwr.isDone) await Task.Delay(5);
 
             if (uwr.isNetworkError || uwr.isHttpError) Debug.Log($"{uwr.error}");
             else
             {
                 clip = DownloadHandlerAudioClip.GetContent(uwr);
             }
         }
         catch (Exception err)
         {
             Debug.Log($"{err.Message}, {err.StackTrace}");
         }
     }
 
     return clip;
 }


Comment
Add comment · Show 1 · 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 fgeorg_oculus · May 07, 2021 at 02:06 AM 1
Share

This worked for me on Windows, but not on Android. For Android it worked once I prefixed the path with the proper "file://" uri scheme. e.g.

 var builder = new UriBuilder(path) {Scheme = Uri.UriSchemeFile};
 var uri = builder.ToString();
 using (UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(uri, AudioType.WAV))
avatar image
0

Answer by mgstauff · Nov 15, 2020 at 07:41 PM

For runtime loading of audiofiles from filesystem you can use AudioImporter: https://github.com/Hello-Meow/AudioImporter

Use the bass audio library plugin to support more formats.

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
avatar image
0

Answer by Flavosky · Feb 08, 2021 at 10:29 PM

Hello everyone,

I would like to add Audio Importer to a Game Object and when I right click on it, that opens the Audio Importer Browser. An idea ?

(I am Sound Designer and C# is pretty difficult to me so.. :/)

Thanks a lot !

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

92 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can you load an AudioClip from the file system w/o using WWW? 0 Answers

Webplayer crash on LoadImageIntoTexture call 1 Answer

Is it possible to load a script from a url? 1 Answer

the texture appear rubbish 1 Answer

iOS - WWW Doesn't work on Local Load 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