Is there a way to preload music?

Monkey Forums/Monkey Programming/Is there a way to preload music?

Grey Alien(Posted 2013) [#1]
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.


therevills(Posted 2013) [#2]
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...


Grey Alien(Posted 2013) [#3]
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...


muddy_shoes(Posted 2013) [#4]
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.


Grey Alien(Posted 2013) [#5]
That's a good idea for non-looping music.


muddy_shoes(Posted 2013) [#6]
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.


MikeHart(Posted 2013) [#7]
For sounds you could use LoadSoundAsync.