- Home /
User choose audio from HardDisk/Cd
How to give the user the ability to choose the audio file(wav,mp3,ogg, etc) from his/her harddisk or CD and play it in a unity game? Note: I mean unity game does not contain that audio file but the user has it on his/her harddisk or CD.
Alternative Question: If this is not possible through programming/scripting nice user interface, is it possible for the user manually (ex, drag his MP3 file and "rename it" and put in a target folder saw unity game can "read" or play it?
Answer by Sebas · Feb 10, 2010 at 08:02 PM
It sounds like you are looking for a file browser for the user to choose a local file. Have a look at these questions:
You can find an example of a browser in the wiki (link) or this link might help (link)
Once the file is selected, you load the file and treat it like a normal audio clip.
unity can just play ogg files and you should load them with www. to read other file formats like wave you need to convert them to ogg or use a plugin to play them.
Answer by Ashkan_gc · Feb 11, 2010 at 04:56 AM
you can use the WWW class and it's audioclip property to load a file and play it. when you want to download the file if you put "file://path" inside the constructor of the class you can load files from the disk. the file should be in ogg format and you need a command line program or plugin to convert wave/mp3 files to ogg or you should play them using a plugin. in windows you can use windows media player's COM component or mci. i don't know about mac osx. the sample included in the above link shows you how to play audio. you should use a "file::path.ogg" as url string.
Your answer
Follow this Question
Related Questions
Audio Question 2 Answers
Replacing Audio Files 0 Answers
Reading Wav file from a folder 0 Answers
GUI.Button Hover = Sound 1 Answer
Input a string and the computer answers with a command? 4 Answers