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 HUD Music Player  

HUD Music Player

long term player for MP3 files

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

the Zip file

Download all files for HUD Music Player
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Music_Script for HUD.lsl
Get file # 2. Sensor for HUD.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 // suitable for museum-like headphone action. Where you stand in front of something and it talks to you until you move away.
3
4 // 10/9/2012
5 // This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
6 // http://creativecommons.org/licenses/by-nc/3.0/deed.en_US
7 // This script cannot be sold even as part of another object, it must always remain free and fully modifiable.
8
9 // This script goes into a prim worn as a HUD.
10 // Drop 10 second song clips in the inventory of the Sensor object, not the HUD.
11 // A great free tool to make these files is the slice audio file splitter at http://www.nch.com.au/splitter
12 //
13 // Set the variable loop = TRUE to loop over and over after reaching the end, set it to FALSE to play once.
14 // Requires another trigger prim in world with the Sensor script in it.
15
16 integer loop = FALSE; // set to TRUE to loop again and again
17 float set_text_alpha = 1; // the text transparency fo alpha text. Set this to 0 to disable hovertext
18 integer debugflag = FALSE; // chat debug info to owner if TRUE
19
20 // Suff that you should not mess with.
21
22 integer waves_to_preload = 3; // wave files to Preload ahead of the wav being played.
23 float preload_load_time = 0.5; // seconds pause between each preloaded wave file attempt b4 play comnences
24 integer secret_channel = 9876; // just a magic number
25 vector set_text_colour = <1,1,1>; // colour of floating text label ( white)
26 list soundQueue; // a list of sound UUIDs from the sensor
27 list nameQueue; // a list of sound names from the sensor
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
33
34 DEBUG (string msg)
35 {
36 if(debugflag) llOwnerSay(msg);
37 }
38
39
40 go(integer play) {
41
42 if(play)
43 {
44 sound();
45
46 } else {
47 llSetTimerEvent(0.0);
49 DEBUG("Stoped");
50 llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
51 }
52 }
53
54
55
56 sound() {
57
58
59 total_wave_files = llGetListLength(soundQueue);
60 integer counter = 0; //do full preload of sound
61 llSetSoundQueueing(TRUE); // only works on llPlaySound not llTriggerSound, so we can queue these silently
62 integer local_total_wave_files = total_wave_files -1 ;
63
64 float length = total_wave_files * 10.0;
65 for (counter = 0 ; counter < waves_to_preload ; counter ++) //preload X wave files b4 we play
66 {
67 key preloading_wave_key = llList2Key(soundQueue,counter);
68 string preloading_wave_name = llList2Key(nameQueue,counter);
69
70 //Attempt to preload first x wave files to local machines cache!
71 llPreloadSound(preloading_wave_key);
72
73 DEBUG("Preloading wav: " + (string)counter + " " + preloading_wave_name);
74
75 llSleep(preload_load_time);
76 }
77
78 llSetTimerEvent(0.1);
79 i_playcounter=0;
80 counter=0;
81 }
82
83
84 default
85 {
87 {
88
89 //set text above object to the name of the object
90 llListen(secret_channel,"","","");
91 llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
92 }
93
94 listen(integer channel, string name, key id, string message)
95 {
96 //DEBUG("Heard:" + message);
97 list msg = llParseString2List(message,["^"],[""]);
98
99 string targetid = llList2String(msg,0); // avatar key to play
100 string cmd = llList2String(msg,1); // stop, queue, or play
101 string soundKey = llList2String(msg,2); // UUID of sound file
102 string soundName = llList2String(msg,3); // UUID of sound file
103
104 if(( key) targetid == llGetOwner())
105 {
106 if(cmd =="queue") {
107 soundQueue += (key) soundKey;
108 nameQueue += soundName;
109 }
110 else if(cmd == "play")
111 {
112 go(TRUE);
113 }
114 else if(cmd == "stop")
115 {
116 soundQueue = [];
117 nameQueue = [];
118 go(FALSE);
119 }
120 }
121 }
122
123 touch_start(integer total_number)
124 {
125 go(TRUE);
126 }
127
128 timer()
129 {
130 llSetTimerEvent(timer_interval);
131 if( i_playcounter > (total_wave_files -1) )
132 {
133 if(!loop)
134 {
136 }
137 else
138 {
139 sound();
140 }
141
142 } else {
143 key playing_wave_key = llList2Key(soundQueue, i_playcounter);
144 string playing_wave_name = llList2String(nameQueue, i_playcounter);
145 DEBUG("llPlaySound wav: " + (string)i_playcounter + " " + (string)playing_wave_key );
146
147 llSetText("Playing " + (string)i_playcounter + " of " + (string)(total_wave_files -1) , set_text_colour, set_text_alpha);
148
149 llPlaySound(playing_wave_key, 1.0);
150
151 key preloading_wave_key = llList2String(soundQueue, i_playcounter + waves_to_preload);
152 string preloading_wave_name = llList2String(nameQueue, i_playcounter + waves_to_preload);
153
154 DEBUG("Preloading wav:" + (string)(i_playcounter + waves_to_preload) + "\n" +
155 " key: " + (string) playing_wave_key + "\n" +
156 "Preloading sequence: " + (string)(i_playcounter + waves_to_preload));
157
158 llPreloadSound(playing_wave_key);
159 }
160 i_playcounter ++; //increment for next wave file in sequence!
161 }
162
163
164 on_rez(integer param)
165 {
167 }
168 }

HUD Music Player

Music HUD

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
4 // if used in HUD mode, only the avatar wearing the HUD and also in range of some location can hear the sounds/music.
5 // When used in PRIM mode, anyone standing near will trigger the sound.
6
7 // 10-09-2012 by Ferd Frederix
8
9 // This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
10 // http://creativecommons.org/licenses/by-nc/3.0/deed.en_US
11 // This script cannot be sold even as part of another object, it must always remain free and fully modifiable.
12
13
14
15 // Tuneable thing:
16 float range = 5.0; // how far a avatar has to be before sound plays, in meters
17 float howoften = 5.0; // how often we look for avatars. Average time before it detects is half this.
18 // The longer you make this, the less lag it causes.
19
20 // for a HUD, put the player in the HUD and put the sensor somewhere in-world to trigger the HUD
21
22 // best to leave these bits alone
23 integer secret_channel = 9876; // just a magic number
24 list playingKeys; // a list of all avatars that have been controlled
25 list sensedKeys; // a list of avatars within range.
26 integer debugflag = FALSE; // set to true to see it as it works
27
28 DEBUG (string msg)
29 {
30 if(debugflag) llOwnerSay(msg);
31 }
32
33 // send a list of UUIDs to a player
34 Send(key id)
35 {
36 integer i;
38 llSay(secret_channel,(string) id + "^" + "stop" + "^" );
39 for (i = 0; i < j; i++) {
41 key soundKey = llGetInventoryKey(name); // get key of named sound
42 llSay(secret_channel,(string) id + "^" + "queue" + "^" + (string) soundKey + "^" + name + "^");
43 }
44 llSay(secret_channel,(string) id + "^" + "play" + "^" );
45 }
46
47 default
48 {
50 {
51 llSensorRepeat("","",AGENT,range, PI, howoften);
52 }
53
54 sensor(integer total_number)
55 {
56
57 integer i;
58 sensedKeys = [];
59 for (i = 0; i < total_number; i++)
60 {
61 key id = llDetectedKey(i); // get every avatars key that is near us
62 if(llListFindList(playingKeys,[id]) == -1) // if not in the list of HUD's that are playing ...
63 {
64 playingKeys += id; // add them to the playing list
65 Send(id);
66 }
67 sensedKeys += id; // add them to the current list of nearby listeners
68 }
69
70 // now check to see if anyone has left the vicinity and issue a stop command to them
71 i = 0;
72 while(i < llGetListLength(playingKeys))
73 {
74 DEBUG("i=" + (string) i);
75 key id = llList2Key(playingKeys,i);
76 if(llListFindList(sensedKeys,[id]) == -1) // if not in sensed, stop them
77 {
78 llSay(secret_channel,(string) id + "^" + "stop");
79 playingKeys = llDeleteSubList(playingKeys,i,i); // remove this person, no longer playing
80 } else {
81 DEBUG((string) id + " is nearby");
82 i++; // look at next person, as this one was still nearby
83 }
84 }
85 }
86
87 no_sensor()
88 {
89 integer i;
90 integer j = llGetListLength(playingKeys);
91 for (i = 0; i < j; i++)
92 {
93 key id = llList2Key(playingKeys,i);
94 llShout(secret_channel,(string) id + "^" + "stop");
95 }
96 playingKeys = [];
97
98 }
99
101 {
103 }
104 }

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