Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: Psyke's Music Script v4.15.1 //Song Player

Psyke Phaeton
Psyke's Defense Systems
Join date: 12 Oct 2003
Posts: 197
03-06-2004 16:54
CODE

//Modified by Psyke Phaeton... this script is free for anyone to use or copy.. please make it copyable from your "CD"

//Drop 9 second song clips in reverse order into the Inv of the obect, and touch to play.

//user variables

integer waves_to_preload = 3; //wave files to Preload ahead of the wav being played.
float preload_load_time = 0.5; // seconds pause between each preloaded wave file attempt b4 play comnences
//vector set_text_colour = <,0,0>; // colour of floating text label
float set_text_alpha = 1; //no idea what this is LOL
float timer_interval = 8.9; //time interval between requesting server to play the next 9 second wave
// times just below 9 seconds are suitable as we use sound queueing
integer timer_started;

// program variables
list invlist;
integer total_wave_files; //number of wave files
integer last_wave_file_number; //final wave sequence number (note: sequence starts at zero
//- so this is 1 less than total wave files)
integer i; //used by timer() player
integer c; //user by sound() bufferer
string preloading_wave_name; //the name of the wave file being preloaded
string playing_wave_name; //the name of the wave being played
integer play = FALSE; //toggle for music playing or stopped

sound()
{
total_wave_files = llGetInventoryNumber(INVENTORY_SOUND);
last_wave_file_number = total_wave_files - 1; // because wav files are numbered from zero
float length = total_wave_files*9.0;
//llSay(0, "preloading " + (string)tottrack + " wavs. Play length " + (string)llFloor(length) + "secs");
integer c = 0;
//do full preload of sound
llSetSoundQueueing(TRUE); //ONLY WORKS ON llPlaySound not llTriggerSound
/////////////////
//integer x = waves_to_preload;
//if ( total_wave_files < waves_to_preload ) { x = total_wave_files; }
////////////////
integer x = total_wave_files;
llSay(0, "(" + llGetScriptName() + ") " + llGetSubString((string)(x * preload_load_time),0,3) + " sec buffering..");
timer_started = FALSE;
for (c = 0 ; c <= (x - 1) ; c++) { //preload X wave files b4 we play
//since wavs are numbered from 0 we minus 1
preloading_wave_name = llGetInventoryName(INVENTORY_SOUND, c);
llSetText(llGetObjectName() +
"\n(preloading " + llGetSubString((string)((x - c)*preload_load_time),0,3) + " secs)"
//////debug lines
//+ "\n--debug--\n"
//+ "Preload wav: " + (string)c
//+ " name: " + preloading_wave_name
//+ "\nkey: " + (string)llGetInventoryKey(preloading_wave_name)
//////end debug line
+"\n.", <1,0,0>, set_text_alpha);

//Attempt to preload first x wave files to local machines cache!
llTriggerSound(preloading_wave_name, 0.0);
llPreloadSound(preloading_wave_name);
//llWhisper(0, (string)c + " of " + (string)tottrack);
//llWhisper(0,"Preloading wav: " + (string)c + (string)llGetInventoryKey(preloading_wave_name));

//start play sound timer in 'timer_interval' seconds when we are less than 'timer_interval' seconds from
// finishing preloading.
if ( ((total_wave_files - c) * preload_load_time) < timer_interval && !timer_started) {
//llWhisper(0, "Starting timer:" + (string)timer_interval);
llSetTimerEvent(timer_interval);
timer_started = TRUE;
}

llSleep(preload_load_time);
}
i=0; c=0;
llSay(0, "Done! Playing.. (" + (string)llFloor(length) + " secs) Click to stop.");
//llSetTimerEvent(8.85);
}

default
{
on_rez(integer start_param)
{
//set text above object to the name of the object
llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
//llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
}
touch_start(integer total_number)
{
if (!play) {
//llTargetOmega(<0,0,1>,PI,1.0) ;
sound();
} else {
//llTargetOmega(<0,0,1>,0,0);
llSetTimerEvent(0.0);
llStopSound();
//llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
llSay(0, "Stopping..");
llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
}

play = !play;
}

timer()
{
if( i > last_wave_file_number )
{
//llSay(0, "finished.");
play = FALSE;
//llSetSoundQueueing(FALSE); //ONLY WORKS ON llPlaySound not llTriggerSound
llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
//llResetScript();
llSetTimerEvent(0);
}
else
{
playing_wave_name = llGetInventoryName(INVENTORY_SOUND, i);
//llWhisper(0, "llPlaySound wav: " + (string)i + " " + (string)llGetInventoryKey(playing_wave_name) );
llPlaySound(playing_wave_name, 0.7);
llSetText( llGetObjectName() +
"\n(playing " + (string)i +" of "+ (string)last_wave_file_number +")\n."
, <0,1,1>, set_text_alpha);

if(i + waves_to_preload <= last_wave_file_number)
{
preloading_wave_name = llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload);
//llSetText( llGetObjectName() +
// "\n(playing " + (string)i +" of "+ (string)last_wave_file_number +")"
//////debug line
//+ "\n--debug--\n"
//+ "Playing key: " + (string)llGetInventoryKey(playing_wave_name) + "\n"
//+ "Preloading sequence: " + (string)(i + waves_to_preload)
//+ " name: " + preloading_wave_name
//+ "\nPreloading key: " + (string)llGetInventoryKey(preloading_wave_name)
//////end debig line
// , set_text_colour, set_text_alpha);

//llWhisper(0, "Preloading wav:" + (string)(i + waves_to_preload) + " " +
// (string)llGetInventoryKey(preloading_wave_name) +" last = " + (string)last_wave_file_number);
llTriggerSound(llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload), 0.0);
llPreloadSound(llGetInventoryName(INVENTORY_SOUND, i + waves_to_preload));
}
}

i++; //increment for next wave file in sequence!
}
}
nunnet Market
Registered User
Join date: 6 Feb 2007
Posts: 1
tx
04-07-2007 13:56
thank u sooooooo much for this script i have made my a i pod mainyl baised on this script

TX
U ARE SOOOOOOOOO COol
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
04-09-2007 05:17
/15/67/10576/1.html
_____________________
i've got nothing. ;)
Roofus Kit
Registered User
Join date: 12 Dec 2006
Posts: 10
03-03-2008 18:07
Any idea why this script skips the third file being played every time?
Alicia Sautereau
if (!social) hide;
Join date: 20 Feb 2007
Posts: 3,125
03-03-2008 21:03
From: Roofus Kit
Any idea why this script skips the third file being played every time?

could be because it`s 3 and a half! years old and a *tad* out dated?
_____________________
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
09-04-2008 19:18
Dust in the grooves, I suspect.

Seriously though, does this script work properly, not skipping the third file every time as described? As properly as SL allows, that is.

=== edit =====

I have been advised that I need to remove this post on the grounds of it being a necropost. that I never be allowed to live it down.

Pffft. I have no reputation to lose. I came acrosss this script while searching for the answer to to a question posted today, this script and this script only. The script may be old but if there's a bug in the script, the bug is current.

At any rate, maybe someone could take a look at /54/d9/280397/1.html and see if you can answer the question.
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
09-04-2008 19:25
NOOOO SuezanneC, not you! You necroposted!!!!!

LOL guess it happens to the best of us :p
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum