Since Unity iPhone still doesn’t have streaming audio capability, we are forced to pre-load audio into memory before we can play it. That’s bad. Especially considering how little memory we have to play with. Audio is always huge, which means 3-5meg of ram could be wasted just on a single song!
Also, it’s frustrating that you can’t play music as your game is loading. Not playing music through the loading process drops your production value a lot. Trying to play music in Unity, during a scene load, ends up with horrible cutting off.
That’s why I hacked… ahem… carefully crafted together a streaming audio system in xcode for Unity iPhone.
Hopefully I’m not missing anything in my little ‘how to get this going’ post! I’m pretty new to obj-c, though I’ve tested this a LOT and it appears to be all good - I take no responsibility if your project explodes, though, m’kay?
Please remember that if you expand this lib, share it back with the community … it’s the right thing to do
Cheers!
Known issues:
Slight pulsing every half second or so when you load the cpu. Buffering perhaps? - anybody got any ideas on this? No volume control. As an obj-c noob, I started adding it but I messed it up!
I’m also getting a frame rate glitch around ever half second. I’m assuming this is because I’m not calling the music the right way with the above syntax.
Sorry to keep posting, I know you’re crunching right now! This code is a life saver though if I can get it working. Getting memory issues because of music.
Hmmm … try calling stop, then set filename, then play.
What worries me is the framerate glitch you’re mentioning … sounds like you are seeing a glitch every time the code checks for updates in those prefs. I hope it’s not something to do with the update loop and the way your unity game gets updated or something odd like that.
Since I don’t see the glitch myself, I’m not sure what it could be … I’ll try making a test bed here and see if I can repro it.
I just did a complete re-factor of my music controller to add in the option to use the streams. Once Psychicparrot has ironed out the bugs and I’ve had a chance to test my code works I’ll post it here.
Basically it’ll handle streamed and non-streamed (for in editor testing) music and should in theory handle looping music on the streams so long as you give it the length of the track in seconds. Completely untested as of now but the looper should also handle you pausing and un-pausing a track.
Once it’s all working I’ll add it here as a generic controller if anyone needs it.
Good luck with the bug tracking. I think a lot of people here are going to find this streamer very very useful!!
Sorry about this! I thought it was working OK and once you mentioned it, I looked at it a little more and realized just how messed up it is!
The bug is in the prefs code somewhere, in that it isn’t resetting the prefs once it checks them … so the file-name is getting checked over and over again and it’s causing the frame delay.
In the original version, it wasn’t resetting the track either when you set the filename.
I really messed it up lol - I will find a way to fix this and get it back up here soon.