I’m wanting to allow the player to select a folder full of MP3 files and use them for a personal soundtrack, like the Radio feature in Grand Theft Auto.
I figured a good first step was to allow the player to provide five MP3s as vars that would then play one after another as one shots, then I would work on the folder idea after I get something out of that.
I’m still not very good at Java, but this is what I have so far, attached to my maincamera object. Not surprisingly, I guess, nothing is happening.
var Song1 : AudioClip = null;
var Song1Volume : float = 1.0;
var Song2 : AudioClip = null;
var Song2Volume : float = 1.0;
var Song3 : AudioClip = null;
var Song3Volume : float = 1.0;
var Song4 : AudioClip = null;
var Song4Volume : float = 1.0;
var Song5 : AudioClip = null;
var Song5Volume : float = 1.0;
function FixedUpdate() {
PlaySong = gameObject.AddComponent(AudioSource);
if(! PlaySong.playOnAwake) {
PlaySong.PlayOneShot(Song1);
PlaySong.PlayOneShot(Song2);
PlaySong.PlayOneShot(Song3);
PlaySong.PlayOneShot(Song4);
PlaySong.PlayOneShot(Song5);
}
}
What am I doing wrong here, and what is the best way to go about playing a folder full of MP3s, or to build a playlist to load the songs?
MP3 is not supported outside the iphone where Apple pays its license
You need to provide it as OGG to be able to load it with WWW.
Finding folder and all files to load would be done through System.IO and is available on standalone only
Thank you for the quick reply.
This idea is for standalone, not I-phone or webplayer. I am using Unity Free for now.
I have already played single MP3 songs in the game, selected as normal audio clips. In fact, I believe the new car tutorial allows this in its sound controller script.
Thanks for the tip on System.IO
Would it still be recommended to convert to OGG?
I am an old C++ programmer, returning to work after 10 years of absence. I’m ok working with C# so far, but not very advanced. Java is a little trickier for me to get my head around. I am an old dude after all.
Sure, but I think what Dreamora is telling you is that Unity has already (internally) converted these audio clips to OGG. There are some pretty extensive licensing restrictions to MP3, so this could well be a factor.
I believe that Unity is now using FMod as the audio API, and I also believe that FMod does not provide a license for MP3 use. So you would almost certainly have to pay that fee yourself, and I think it’s a considerable sum. I guess the only way around it would be to use a third party library via a C++ plugin, and even then I’m not sure which (if any) audio libraries include the MP3 license.
Yes, I would recommend to convert to OGG unless you want WAV, otherwise loading will become impossible basically.
As for FMOD: even if they had an mp3 license you can’t use it. The application that does the playback has to pay for the license, so even if fmod had it, you would still have to pay the thousands for it.
on the iphone this does not hold because the playback is done through the os and device, which are covered, as mp3 player, through apples license
OK then, thanks, guys. I’m not sure if I made it clear. The idea here is for the end users to select files on their own computer, that they themselves have ripped, not for the music files to be included in the game assets.
I’ll either provide info about converting to the users, or package a freeware converter with the game app, to convert files to OGG format. I’ll probably also include a small list of royalty-free tunes for the soundtrack.
This is intended to be an optional feature, sort of, not really a big part of things. That’s how it is in Grand Theft Auto. They just describe to you in the docs how to set up a folder of songs that you point the game to, and after that one of your radio station selections allows you to play your own music while driving the cars.
Now to get with the System.IO pursuit, and see what I can do to create a jukebox script.
Thanks!
I used MP3s in a game I developed. They played fine, but there was a tiny bit of silence after each file played. (I was looping each file, and the beat got … offbeat.)
There might be other problems I don’t know about but that’s the only one I encountered.
In the “SoundController.JS” script included with the new car tutorial, there is a slot provided to choose background music. I tried putting my own rips into that slot and they worked fine. I had to convert them from WMA files to MP3 for them to work, though.
So I guess from what was said above, that the Unity software converts from MP3 to OGG before playing the file, to solve the licensing issues.