Help me! simple audio code

Blitz3D Forums/Blitz3D Beginners Area/Help me! simple audio code

mimox(Posted 2010) [#1]
Please someone can help me or shom me some examples, I have to on and off a music (mp3) with the keys keyboard, example: I would like to do this way: When I press Key 1 the music go to play, if I press 2 go to stop. I'm beginner!

Thank you again


Serpent(Posted 2010) [#2]
You posted this in the programming area as well and it's already been answered... But I feel like answering anyway.

Const StartKey = 2, StopKey = 3

Sound = LoadSound("Your Sound Here.mp3")

Channel = PlaySound(Sound)


While Not KeyHit(1) ;Repeats until the user presses the escape key

If KeyHit(StopKey) Then PauseChannel Channel      ;If the user presses 'StopKey' (which is '2') then pause the sound
If KeyHit(StartKey) Then ResumeChannel Channel    ;If the user presses the key 'StartKey' (which is '1') then resume the sound

Wend

End


If you want to control sounds in your program, you will have to use channels. Basically, whenever you play a sound in Blitz, the function PlaySound will return a variable specifying the 'channel' that the sound is using to play. You can then use functions such as PauseChannel and ResumeChannel to modify the sound that is currently playing.


mimox(Posted 2010) [#3]
Thank you :-)