Just a newbie question...

Blitz3D Forums/Blitz3D Beginners Area/Just a newbie question...

Hybird(Posted 2003) [#1]
Err...how do you make a sound file play?? I want to play an mp3 file, and I know how to load it, but I'm not quite sure how I'd play it. Something to do with channels??? As you can tell, I'm a complete newbie to programming :)

Thanks


soja(Posted 2003) [#2]
Pretty simply. Look up PlaySound (of all commands) in the documentation. Make sure you're assigning the returned handle from LoadSound to a variable ("song" in this case). Then specify that as the PlaySound parameter.
song = LoadSound("C:\Music\music.mp3")
PlaySound(song)



Hybird(Posted 2003) [#3]
Global Music

Music= LoadSound ("music.mp3")

PlaySound (Music)

Didn't quite work. This is what I put in. I made 'Music' a global variable, but I keep getting a box saying sound doesn't exist. What am I doing wrong? Help appriciated.

Thanks


soja(Posted 2003) [#4]
Blitz will look for the file in the same folder that your source file is at. If you haven't saved it yet, it will look in the "tmp" folder (at least in BlitzPlus -- I'm not sure about in Blitz3D). So either specify the full path (with drive letter), or a relative path from where the sourcecode file is.

Also, make sure you put a waitkey or notify or something at the end of the program so it doesn't terminate as soon as it starts loading/playing the music.


Hybird(Posted 2003) [#5]
I put the full path of the mp3 in, double checked the file was spelt right, saved the source code, but I'm still getting the 'no sound exists' error :S


Hybird(Posted 2003) [#6]
Could you please write out the full code correctly for me? I'm not having much luck :)

Thanks


ronbravo(Posted 2003) [#7]
You could try:
------------------------------------------------

Graphics 320, 240, 16, 2
SetBuffer BackBuffer()

Music = PlayMusic( "C:\WINDOWS\Media\town.Mid" )
Print "Playing Song..."

While KeyHit( 1 ) <> 1
Wend

End

------------------------------------------------
If that doesn't help then post your code and we'll see what we can do.


Hybird(Posted 2003) [#8]
Ak. That didn't work either :( I posted my code a few posts before. It either doesn't play or I get the 'no sound exists' box pop up. Not sure what I'm doing wrong. I put in the full address. Is it how I setted the code out??
Help very much appriciated.

Thanks


Hybird(Posted 2003) [#9]
Ahh, I'll just post the code again :) The mp3 file is in the same folder as the source code.

Global Music

Music= LoadSound ("music.mp3")

PlaySound (Music)


ronbravo(Posted 2003) [#10]
Maybe it's the mp3 file. You could try a differnt mp3. I don't know if you used the exact path directory in my example but you could try an .mid formated song just to make sure Blitz is still working properly. Let me know what happend.


Foppy(Posted 2003) [#11]
edit: Mojokool actually mentioned the PlayMusic command, I missed that...

I think you need the PlayMusic command (as opposed to using LoadSound and PlaySound). In the help files under PlayMusic it says:

You can't 'preload' the audio like you can a sound sample via the LoadSound command.


This means you have to load the music the moment you want to use it. Using PlayMusic you specify where the file is to be found and it will load it *and* start playing. You can assign the music to a channel to change things like the volume, and to switch it off again:

Global music

; start playing music:
music = PlayMusic("music.mp3")

; change the volume to 0.9 (as an example):
ChannelVolume(music,0.9)

; stop playing music:
StopChannel(music)



soja(Posted 2003) [#12]
It's always a good idea to check the return value of a function for success or failure, too.

Check to see that music <> 0 (fail) before you try to play it.


Hybird(Posted 2003) [#13]
I tried using a different mp3 file, and hey, it worked! :) I guess the other mp3 file I used was probably corrupted. Thanks, everyone, for your help! :)