playmusic/playsound question

Previous topic - Next topic

Gary

Hopefully someone here can give me a simple solution to this problem

I have a sound that is loaded as a wav file at program start up that I want to play as a continuous loop at certain times. Currently I am using PLAYSOUND and checking if the channel is still playing and restarting if it isn't but my problem is if the music stops when it is out of the loop doing something else I get a pause. I see that PLAYMUSIC can be set to run and just play in the background as a looping tune but from the docs it looks like PLAYMUSIC requires the sample to be loaded at the time of playing rather than specifying a sound number that is already loaded. This would be difficult to use as I jump all over the place saving files.

I also notice that you can set a buffer value on LOADSOUND between 1 and 4 that states the number of times the sample can be played without interruption, I assume it just duplicates the sound x number of times. Setting this to 4 cures the problem a little bit but not totally.

Can PLAYMUSIC be used with a preloaded sample or is there any way that PLAYSOUND can be set to loop and forget until the sample is killed with a HUSH?

Thanks
Gary

Gary

not sure if its best practice but I have specified the full path for the wav file in PLAYMUSIC, could this cause implications elsewhere in directories getting changed?

mentalthink

Hi Gary, whit sounds you have to take care, becuase in PC don´´t runs equal than other platforms... if I understood well, you say don´t have a perfect loop, if you don´t try over a mobile device try it... sometime ago, I try to make a simple BeatBox, and was very difficult make the sonds playing equal than PC...

I think in the forum, somebody speaks about to makes a perfect loop, but I don´t know this info...

A trick, but I´m not sure if can works, it´s make something whit 2 playsmuics commands , like concatenate them... perhaps you can solve the trouble, but how I say I´m not sure about this patch...

Kinds Regards

Wampus

AFAIK there is no ideal solution to what you're asking. PLAYSOUND has no infinite loop and PLAYMUSIC only works with streaming files - no preload.

There was a thread on looping sounds that I think mentalthink was referring to. Its here: http://www.glbasic.com/forum/index.php?topic=3917 I've used something similar to the technique from that thread and it works well enough.

Quote from: Gary on 2011-Dec-20
not sure if its best practice but I have specified the full path for the wav file in PLAYMUSIC, could this cause implications elsewhere in directories getting changed?

Oh, yes, most probably. Best to store your media files in a media folder placed in the game's root directory, then change the directory at startup with SETCURRENTDIR("Media").

Even better, when your program first runs it can be helpful to store the launch directory as a string. e.g. GLOBAL dir$ = GETCURRENTDIR$(). You can use this as an anchor. No matter which directory your app is set to, you can easily return to the Media folder (or any other folder within the game root directory) with SETCURRENTDIR(dir$+"Media")