Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Music Music Player  

Music Player

Sensor

Category: Music
By : Ferd Frederix
Created: 2013-09-06 Edited: 2013-09-04
Worlds: Second Life

the Zip file

Download all files for Music Player
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Music_Script.lsl
Get file # 2. Sensor.lsl

This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1
2 // 10-09-2012 by Ferd Frederix
3
4 // May be triggered to run continually, start it by touching it or use the sensor script when someone gets nearby.
5
6 // This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
7 // http://creativecommons.org/licenses/by-nc/3.0/deed.en_US
8 // This script cannot be sold even as part of another object, it must always remain free and fully modifiable.
9
10 // Drop 10 second song clips in the inventory of the obect, and touch to play.
11 // A great free tool to make these files is the slice audio file splitter at http://www.nch.com.au/splitter/index.html
12 // Set the variable loop = TRUE to loop after reaching the end, set it to FALSE to play once.
13
14 // Scriptable Control:
15 // Send a link message string of 'play' and 'stop' for use with external control scripts.
16 // Or just touch the prim to play
17
18 integer loop = FALSE; // set to TRUE to loop again and again
19 float set_text_alpha = 1; // the text transparency fo alpha text. Set this to 0 to disable hovertext
20
21 // Stuff that you should not mess with:
22
23 integer debugflag = TRUE; // chat debug info to owner if TRUE
24 integer waves_to_preload = 3; // wave files to Preload ahead of the wav being played.
25 float preload_load_time = 0.5; // seconds pause between each preloaded wave file attempt b4 play comnences
26 integer secret_channel = 54345; // just a magic number
27 vector set_text_colour = <1,1,1>; // colour of floating text label ( white)
28 float timer_interval = 9.8; // time interval between requesting server to play the next 10 second wave
29 // times just below 10 seconds are suitable as we use sound queueing
30 integer total_wave_files; // number of wave files
31 integer i_playcounter; // used by timer() player
32 string preloading_wave_name; // the name of the wave file being preloaded
33 string playing_wave_name; // the name of the wave being played
34
35
36 DEBUG (string msg)
37 {
38 if(debugflag) llOwnerSay(msg);
39 }
40
41
42 go(integer play) {
43
44 if(play)
45 {
46 sound();
47
48 } else {
49 llSetTimerEvent(0.0);
51 DEBUG("Stoped");
52 llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
53 }
54 }
55
56
57
58 sound() {
59
60
61 total_wave_files = llGetInventoryNumber(INVENTORY_SOUND);
62 integer counter = 0; //do full preload of sound
63 llSetSoundQueueing(TRUE); // only works on llPlaySound not llTriggerSound, so we can queue these silently
64 integer local_total_wave_files = total_wave_files -1 ;
65
66 float length = total_wave_files * 10.0;
67 for (counter = 0 ; counter < waves_to_preload ; counter++) //preload X wave files b4 we play
68 {
69 //since wavs are numbered from 0 we minus 1
70 preloading_wave_name = llGetInventoryName(INVENTORY_SOUND, counter);
71
72
74 + "Preload wav: " + (string)counter +"\n."
75 +"\n.", <1,0,0>, set_text_alpha);
76 //Attempt to preload first x wave files to local machines cache!
77 llPreloadSound(preloading_wave_name);
78
79
80 DEBUG("Preloading wav: " + (string)counter + " " + (string)llGetInventoryKey(preloading_wave_name));
81 //start play sound timer in 'timer_interval' seconds when we are less than 'timer_interval' seconds from
82 // finishing preloading.
83 llSleep(preload_load_time);
84
85 }
86 llSetTimerEvent(0.1); // start playing
87 i_playcounter=0;
88 counter=0;
89 }
90
91
92 default
93 {
95 {
96 //set text above object to the name of the object
97 llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
98 }
99
100 touch_start(integer total_number)
101 {
102 go(TRUE);
103 }
104
105 timer()
106 {
107 llSetTimerEvent(timer_interval);
108 if( i_playcounter > (total_wave_files -1) )
109 {
110 if(!loop)
111 {
113 }
114 else
115 {
116 sound();
117 }
118
119 } else {
120 playing_wave_name = llGetInventoryName(INVENTORY_SOUND, i_playcounter);
121 DEBUG("llPlaySound wav: " + (string)i_playcounter + " " + playing_wave_name );
122
123 llPlaySound(playing_wave_name, 1.0);
124 llSetText( llGetObjectName() + "\n(playing " + (string)i_playcounter +" of "+ (string)(total_wave_files -1) +")\n.", <0,1,1>, set_text_alpha);
125 if(i_playcounter + waves_to_preload <= (total_wave_files -1))
126 {
127 preloading_wave_name = llGetInventoryName(INVENTORY_SOUND, i_playcounter + waves_to_preload);
128 llSetText("Playing " + (string)i_playcounter + " of " + (string)(total_wave_files -1) , set_text_colour, set_text_alpha);
129
130 DEBUG("Preloading wav:" + (string)(i_playcounter + waves_to_preload) + "\n" +
131 (string) llGetInventoryKey(preloading_wave_name) + "\n" +
132 "Preloading sequence: " + (string)(i_playcounter + waves_to_preload));
133
134
135 llPreloadSound(llGetInventoryName(INVENTORY_SOUND, i_playcounter + waves_to_preload));
136 }
137 }
138 i_playcounter++; //increment for next wave file in sequence!
139 }
140
141 link_message(integer sender_number, integer number, string message, key id)
142 {
143 if(message == "play")
144 {
145 go(TRUE);
146 }
147 else if(message == "stop")
148 {
149 go(FALSE);
150 }
151 }
152
153 on_rez(integer param)
154 {
156 }
157 }

Music Player

Sensor

Category: Music
By : Ferd Frederix
Created: 2013-09-06 Edited: 2013-09-04
Worlds: Second Life


This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1
2 // general purpose avatar sensor for the music playert
3 // When someone gets in range, this starts the music sequence if a HUD or if the player is in the same prim
4 // 10-09-2012 by Ferd Frederix
5
6 // This work is licensed under a Creative Commons Attribution 3.0 Unported License.
7 // http://creativecommons.org/licenses/by/3.0/deed.en_US
8
9
10 // Tuneable thing:
11 float range = 5.0; // how far a avatar has to be before sound plays, in meters
12 float howoften = 5.0; // how often we look for avatars. Average time before it detects is half this. The longer you make this, the less lag it causes.
13 integer debugflag = FALSE;
14
15 // best to leave these bits alone
16
17 integer someoneIsListening = FALSE; // if TRUE, the player is running in PRIM mode
18
19 DEBUG (string msg)
20 {
21 if(debugflag) llOwnerSay(msg);
22 }
23
24
25 default
26 {
28 {
29 llSensorRepeat("","",AGENT,range, PI, howoften);
30 }
31
32 sensor(integer total_number)
33 {
34 if(!someoneIsListening)
35 {
36 someoneIsListening = TRUE;
37 llMessageLinked(LINK_SET,0,"play","");
38 }
39
40 }
41
42 no_sensor()
43 {
44 if(someoneIsListening)
45 {
46 someoneIsListening = FALSE;
47 llMessageLinked(LINK_SET,0,"stop","");
48 return;
49 }
50
51 }
52
54 {
56 }
57 }

Back to the Best Free Tools in Second Life and OpenSim.