Music problems/questions

Monkey Targets Forums/HTML5/Music problems/questions

Sensei(Posted 2014) [#1]
Hey guys,

I've started implementing music in my game now. Just so you know, sounds work fine on all platforms tested.
In the OnCreate method I started with a simple PlayMusic(currentSong, 1).
Then in the menu system of the game (during the OnUpdate() method), I have options to toggle sound and music. Again, sounds play/don't play depending on if I've toggled it to be on or off with a simple variable state check: If soundEnabled = 1 ...play sound.
However, I am having difficulties using music.
Initially, the music plays (thanks to the OnCreate PlayMusic() method)., but when I toggle the music option, it stops playing, but won't start up again.
I have made the code print out to the console the state of MusicState(), musicEnabled (my toggle variable) and currentlyPlaying (another toggle variable).
I use it as thus:
If musicEnabled = 1
 if currentlyPlaying = 0
    StopMusic() ' Not sure if I need to do this here but it's an incase
    PlayMusic(currentSong, 1)
    currentlyPlaying = 1
  End
Else
  If currentlyPlaying = 1
    StopMusic()
  End
  currentlyPlaying = 0
End

When you toggle the option to enable music, you get:
currentlyPlaying: 1
MusicState: 1
musicEnabled: 1

And when you turn it off you get:
currentlyPlaying: 0
MusicState: 0
musicEnabled : 0

So I know my parameters appear to toggle correctly, and the logic seems to make sense to me.
So as mentioned above, the music stops, but then won't start up again.

I am testing this in HTML5 with an mp3 file. Unfortunately I don't have a .wave file to test with using GLFW at the moment, so wasn't able to test it on there to see if it's just an HTML issue.

Anyone have some examples of music code or suggestions on how better to implement it in Monkey?


Sensei(Posted 2014) [#2]
Update:

Well this turned out to be a flaw in the monkey web server/HTML5.
When I used a .wav file in GLFW, it worked fine. Just had to tweak my game/menu logic to play, stop, pause and resume the music. Happy days.

Still, the fact that you pass a Sound type in Playsound() and a String in PlayMusic() is just stupid and confusing.


Yoda(Posted 2014) [#3]
I just changed the musicvolume when you click the toggle-music button.