Change music during the gameplay

Monkey Targets Forums/Android/Change music during the gameplay

lom(Posted 2016) [#1]
Is it possible to change current music track during the actual gameplay without delays? Because when I call PlayMusic() it freezes the game for about a second. I guess it takes time to load another track. It would be so much easier to play music with sound channels, but sound length is very limited for android.


Arabia(Posted 2016) [#2]
Are you loading the music and then calling PlayMusic? Can you not load all the tracks you want at the start? or if this isn't possible, put your Load at some point where you can give your game time to load it before stopping the current track if that makes sense. I've honestly never tried to load and play immediately - but loading takes time and keep in mind that users of some Android devices may be even slower than what you are using - so even if it works on your device, and older device may struggle to get the job done.


ElectricBoogaloo(Posted 2016) [#3]
The PlayMusic command streams audio, and is meant to do it relatively quickly. Unfortunately, that's not always the case.
You could attempt to write your own music engine, either playing full instrumental tunes from lines of data, or using loops of music to create a varied soundtrack.. .. But both have pitfalls depending on the target, and what device is used.
My own music engine was seemingly foolproof, until I saw someone playing it through a capture device, and for some really odd reason, the music's timing was roughly quartered, meaning there was one drum beat every few seconds!!!

Complicated stuff, and even then it's still broken. Bah, humbug!


lom(Posted 2016) [#4]
Arabia,
Monkey has no functions to load the music. PlayMusic function uses audio streaming as far as I know and it uses only one channel. If there was at least 2 music channels it would be much more easier.

ElectricBoogaloo,
I see...I never thought that playing music could be so complicated =)


Arabia(Posted 2016) [#5]
@Iom - is it possible to use PlaySound instead? I'm a older user of Monkey, but not very good and never released anything, but I've messed around with PlaySound which does allow you to use channels and it seems to work okay for me. Forgive me if this is totally wrong, but can't you use PlaySound to play a music track in the same way and then play other sounds over other channels? No time for me to muck around tonight and check this for myself.


lom(Posted 2016) [#6]
Arabia,
Playing music through sound channels works perfect for GLFW target. But if I'm playing music through sound channel on Android it plays for only about 10 seconds and then loops. I guess that's because android has a limitations on sound length.