Help with controlling llLoopSound(), please?
|
|
Otis Pertwee
Registered User
Join date: 22 Jan 2006
Posts: 12
|
05-03-2006 07:52
Hi! I'm making a very simple music player. It is an object that will just simply loop the 10 second audio files contained inside it. I'm totally new to SL scripting, moderately experienced with PHP. I know how to simply make the file loop, and I see how to change which audio file is chosen for playing- I would like to give my object text commands [or even better, a diaglogue box] with the following: Start play, Next song, Previous song, Stop play. For the 'Next' and 'Previous' I know that I need to add and subtract from this value: From: someone llLoopSound(llGetInventoryName(INVENTORY_SOUND, 0), 1); I have the idea that I'll need to create a variable that says how many files are inside the object so that when I get to the last file it knows to go back to the first one. If anyone can help me out it'd be greatly appreciated- thank you 
|
|
Neb Soyer
Really good looking.
Join date: 9 Apr 2006
Posts: 45
|
05-03-2006 08:23
I found this script in the forums awhile ago for a friend, I'm pretty sure it works, try it out - you can also use it to analyze and learn from it. integer SOUND_LENGTH = 10; // Each sound is 10 seconds long. float VOLUME = 1.0;
integer curSound; default { // Jukebox off touch_start(integer totalNum) { state playin; } }
state playin { state_entry() { curSound = 0; llSetTimerEvent(0.1); // Trigger ASAP! } timer() { integer numSounds = llGetInventoryNumber(INVENTORY_SOUND); if (curSound < numSounds) { llPlaySound(llGetInventoryName(INVENTORY_SOUND, curSound), VOLUME); } else { state default; } ++curSound; llSetTimerEvent(SOUND_LENGTH); } touch_start(integer totalNum) { llStopSound(); state default; } } It gets all the sounds in the inventory, and plays them in order. So you need to arrange your 10 second sounds in the object's inventory like "sound1", "sound2", etc.
_____________________
down in the ghetto.
|
|
Otis Pertwee
Registered User
Join date: 22 Jan 2006
Posts: 12
|
05-03-2006 08:54
From: Neb Soyer It gets all the sounds in the inventory, and plays them in order. So you need to arrange your 10 second sounds in the object's inventory like "sound1", "sound2", etc.
Thank you! I've seen scripts like this but they aren't really what I was looking to do. I'm just trying to get it to loop a single audio file with the ability of switching which one is currently looping. I'm going to try to figure it out some more and if I can't get it after a few days I'll end up using something like what you showed me. Thanks for replying :}
|
|
Otis Pertwee
Registered User
Join date: 22 Jan 2006
Posts: 12
|
05-03-2006 09:13
Browsing around the forum I have the basics of getting my dialogue box and having it listen on channel -2019. I need to know how I can make the 'Previous' button subtract 1 from the value in llGetInventoryName(INVENTORY_SOUND, 0) and, well, everything else. heh. default{ state_entry() { llListen(-2019,"","",""); } touch_start(integer num) { llDialog(llDetectedKey(0),"JAMBOX.",["Play","Previous","Next","Stop"],-2019); } }
|
|
Otis Pertwee
Registered User
Join date: 22 Jan 2006
Posts: 12
|
Hooray for progress!!
05-03-2006 09:43
I hope someone reads this! Haha. I'm plugging along, learning a lot, and loving this. I never realized that this is pretty much just PHP. It's beautiful. What a blast! I've reached a problem though! For some reason I can't get my llGetInventoryNumber(INVENTORY_SOUND); to work! I get a syntax error. Here is the code so far: // Jambox script by Otis Pertwee! Hooray!!
string BOXTITLE = "JamBOX"; // Title of the dialogue box integer BOXCHANNEL = 0; // Channel the commands will be sent on. (0 for debug) integer SOUNDCOUNT = llGetInventoryNumber(INVENTORY_SOUND);
default{
state_entry() { llListen(BOXCHANNEL, "", NULL_KEY, ""); }
touch_start(integer num) { llDialog(llDetectedKey(0),BOXTITLE,["Play","Previous","Next","Stop"],BOXCHANNEL); }
listen(integer channel, string name, key id, string message) { if (message == "Play") { llLoopSound(llGetInventoryName(INVENTORY_SOUND, 0), 1); } if (message =="Stop") { llStopSound(); state default; } } }
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
05-03-2006 09:49
Without writing all the code for you... llGetInventoryName() will help you get a list of the names of the sounds. llListFindList() will help you convert that name into the index number - which will almost certainly be the same as the number of the sound if you want to do it that, alternatively just feed it the name! You'll need something to cycle through and build up a list of the names of the sounds (state_entry, on_rez and changed events possibly to go to the same list building function). Your dialog script modified to use the list of names generated (as long as there are fewer than 12 sounds) and then llLoopSound() with the sound name... Alternatively you can use your next, previous, first, last list to jump around in the list directly. You'll need something like llList2Sring for that. If that doesn't work I'm sure either I or someone else can point you the right way. Declaring your variable - unlike php you have to declare its type too e.g. integer pointer, string name, list sounds etc. More advice on these functions (and so much more from: http://secondlife.com/badgeo/wakka.php?wakka=HomePage
|
|
Dire Lobo
Registered User
Join date: 20 Dec 2005
Posts: 47
|
05-03-2006 10:03
From: Otis Pertwee I hope someone reads this! Haha. I'm plugging along, learning a lot, and loving this. I never realized that this is pretty much just PHP. It's beautiful. What a blast! I've reached a problem though! For some reason I can't get my llGetInventoryNumber(INVENTORY_SOUND); to work! I get a syntax error. Here is the code so far: // Jambox script by Otis Pertwee! Hooray!!
string BOXTITLE = "JamBOX"; // Title of the dialogue box integer BOXCHANNEL = 0; // Channel the commands will be sent on. (0 for debug) integer SOUNDCOUNT = llGetInventoryNumber(INVENTORY_SOUND);
}
I'm pretty sure you cannot call a function in a var declaration. Declare the var with no value (0) then set it in the state_entry() method.
|
|
Otis Pertwee
Registered User
Join date: 22 Jan 2006
Posts: 12
|
05-03-2006 10:54
Thanks for the advice. I took a look at generating those lists and decided to just plug ahead with the simple addition and subtraction for Next / Previous... I've got a problem with my if / else statement though, it seems! The idea is that IF the 'current song' is less than the 'number of sounds' then it will play the next sound file and add ONE to the 'current song'. ELSE it should play the First (zero) sound file and set 'current song' to Zero... My nexting works beautifully, but once it gets to the last file it's not properly going back to the first file... Any ideas? Here's that portion of code: if (message == "Next") { if (CURRSOUND < SOUNDCOUNT) { ++CURRSOUND; llLoopSound(llGetInventoryName(INVENTORY_SOUND, CURRSOUND), VOLUME); } else { llLoopSound(llGetInventoryName(INVENTORY_SOUND, 0), 1); integer CURRSOUND = 0; } }
And here's the whole thing as it is right now: // Jambox script by Otis Pertwee! Hooray!!
string BOXTITLE = "JamBOX"; // Title of the dialogue box integer BOXCHANNEL = -50; // Channel the commands will be sent on. (0 for debug) float VOLUME = 1.0; // Volume.
default{
state_entry() { llListen(BOXCHANNEL, "", NULL_KEY, ""); }
touch_start(integer num) { llDialog(llDetectedKey(0),BOXTITLE,["Play","Previous","Next","Stop"],BOXCHANNEL); }
listen(integer channel, string name, key id, string message) { integer SOUNDCOUNT = llGetInventoryNumber(INVENTORY_SOUND); integer CURRSOUND = 0; if (message == "Play") { llLoopSound(llGetInventoryName(INVENTORY_SOUND, 0), VOLUME); integer CURRSOUND = 0; } if (message == "Next") { if (CURRSOUND < SOUNDCOUNT) { ++CURRSOUND; llLoopSound(llGetInventoryName(INVENTORY_SOUND, CURRSOUND), VOLUME); } else { llLoopSound(llGetInventoryName(INVENTORY_SOUND, 0), 1); integer CURRSOUND = 0; } }
if (message =="Stop") { llStopSound(); integer CURRSOUND = 0; }
} }
|
|
Kayla Stonecutter
Scripting Oncalupen
Join date: 9 Sep 2005
Posts: 224
|
05-03-2006 11:05
SOUNDCOUNT starts at 1, but CURRSOUND starts at 0, so increase CURRSOUND, then do the check as you have it. if (message == "Next") { ++CURRSOUND; if (CURRSOUND < SOUNDCOUNT) { llLoopSound(llGetInventoryName(INVENTORY_SOUND, CURRSOUND), VOLUME); } else { llLoopSound(llGetInventoryName(INVENTORY_SOUND, 0), 1); integer CURRSOUND = 0; } }Also, please call llStopSound() just before llLoopSound(), otherwise you could get a pop when the sound changes that's audible to everyone around at full volume no matter how loud the sound itself is. There's a free motorcycle out there, along with a few other vehicles, that I hear about once or twice a week doing that; even if it's at the edge of my hearing range, the pop is loud and very annoying. Doesn't always happen, but it's good to get in the habit of doing.
|
|
Otis Pertwee
Registered User
Join date: 22 Jan 2006
Posts: 12
|
05-03-2006 11:25
From: Kayla Stonecutter Also, please call llStopSound() just before llLoopSound(), otherwise you could get a pop when the sound changes that's audible to everyone around at full volume no matter how loud the sound itself is. There's a free motorcycle out there, along with a few other vehicles, that I hear about once or twice a week doing that; even if it's at the edge of my hearing range, the pop is loud and very annoying. Doesn't always happen, but it's good to get in the habit of doing.
Thank you VERY much! These were both really helpful. I almost hit myself on the head when I was overlooking that the inventory number was starting at 0. Also- I was cringing every time I clicked 'Next' due to that pop.
|