Is there a way to preload music?
Monkey Forums/Monkey Programming/Is there a way to preload music?
| ||
Currently PlayMusic takes a path and then loads in a plays the music. This is fine for the most part, but I'm in a situation where I want to play a sound, wait until it's done (I'll just run a timer in code to the approx length) and then trigger the music. However because the music takes a while to load in (and this could vary on different machines), it's not seamless. Sure I could add the sound to the start of the music but I'd rather do this in code. Ideally PlayMusic would have a param like startPaused or something, then ResumeMusic could be used on it later. |
| ||
If your music is short (<1MB) you could load it in as a Sound, PlayMusic will stream it on some targets and load it on others. The Music features are currently very limited on Monkey... |
| ||
OK thanks. One thing I haven't tried is Playing it then immediately pausing it but I'm paranoid it'll make a tiny little sound blip on some devices before the code reaches the pause function... |
| ||
A valid concern. I seem to remember finding that the state wasn't valid immediately after a load on some platforms. You should be able to just put half a second of silence at the start of the music to give you a chance to pause it. |
| ||
That's a good idea for non-looping music. |
| ||
If you need to loop then see if the music can be loaded with the volume at zero, stopped and restarted with the volume up to avoid the latency problems. |
| ||
For sounds you could use LoadSoundAsync. |