I am creating a car game. Is any way to play the music stored on the phone inside the game? I'd like the player to choose files that are already on their device and hear them played in the game.
For example, in GTA Vice City game there was a folder named Music, and if we placed songs in there they would play on the car radio while we're driving around inside the game. If we want to switch the songs around, we can do so. how can I do the same in Android and iOS?
I am using unity 5.2, C#.
Answer
It is possible to do so. Given a directory, unity's WWW class will be able to obtain the file using the URL. You can then create a clip with that file and pass it to the audio source.
Do note that you will have to either hard code a directory on the phone, use a navigator to allow the user to select the folder or create a searcher to find all audio files.
Use file://
to access a local resource. Do take note that different devices have different file structure and you have to adapt for each of them.
No comments:
Post a Comment