Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

CD music?

Mordigant Recreant
Registered User
Join date: 18 Jan 2007
Posts: 19
02-06-2007 14:05
Hi, I'm completely new to scripting. Yesterday I created an object that looks like a CD.

What I want to do is have this CD play one piece of classical music. How would I set this up?

Thanks!
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
02-06-2007 16:51
There's a way to do it, but it's not perfect and costly (especially for lengthy classical music).

You'll need to first use a WAV editor to split your selection into as many 10-sec clips as required. Some folks say it requires 9.9sec clips to work. The maximum length you can upload as a WAV is 10-secs. That's L$10 per 10-secs of music. Once you have all the clips, they need to be placed into your CD object along with a script that plays the clips in order. The first run-through will be choppy, since the clips need to download to your client.

You can probably find some existing records/CDs and modify them rather than re-invent the playback script from scratch. Ask some old-timers from the pre-streaming music days of SL, who might have them.
Max Pitre
Registered User
Join date: 19 Jul 2006
Posts: 370
02-06-2007 20:38
I liked it at first but now I don't use this one. Not sure where I got it so sorry if there isn't reference to the creator.
If I remember right, you have to put the clips in from the last to fist although I could very well be wrong.

CODE



float INTERVAL = 10.00; // 10 secs clips.

string ScriptName ="*John Lennon!!*";

vector Vector_Color = <1.00000, 1.00000, 0.00000>;

float VOLUME = .8;

integer Elite_Sound;
integer Elite_Track;
integer Elite_Playing;
integer Elite_MaxWaves = 1;
integer Elite_List_Count;
integer Elite_TotalTrack;

integer Elite_TotalTracks;
integer Elite_PlaySong = FALSE;

integer AttackCHK = FALSE;

list Elite_g_lTrack;


integer CheckForWaveFiles()
{
integer i;

Elite_TotalTrack = llGetInventoryNumber(INVENTORY_SOUND);

// clear and rebuild the clips list
Elite_g_lTrack = llDeleteSubList(Elite_g_lTrack,0,-1);
for ( i = 0; i < Elite_TotalTrack; i++ )
{
Elite_g_lTrack += llGetInventoryName(INVENTORY_SOUND,i);
}
if (Elite_TotalTrack < Elite_MaxWaves)
{
return TRUE;
}
return FALSE;
}
Elite_PlayTheSong()
{
Elite_PlaySong = TRUE;
llWhisper(0,(string)ScriptName+". Playing Music...");
llAdjustSoundVolume(VOLUME);
Elite_Playing = 1;
llSetSoundQueueing(TRUE);
Elite_Track = llGetInventoryNumber(INVENTORY_SOUND);
llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0),VOLUME);
llPreloadSound(llGetInventoryName(INVENTORY_SOUND, 1));
llSetTimerEvent(5.0); // wait 5 seconds before queueing the second file
Elite_Sound = 1;
}

Elite_StopTheSong()
{
llSetTimerEvent(0.0);
Elite_Playing = 0;
Elite_Sound = 0;
Elite_PlaySong = FALSE;
llStopSound();
llResetScript();
}
default
{
state_entry()
{
Elite_Playing = 0;
Elite_Sound = 0;
llSetText(llGetObjectName(),Vector_Color,10);
}

attach(key id)
{
if (id == NULL_KEY)
{
return;
}
else
AttackCHK = TRUE;
Elite_Playing = 0;
Elite_Sound = 0;
Elite_PlayTheSong();
}
on_rez(integer start_param)
{
}
touch_start(integer total_number)
{
integer CheckAccess;
key person = llDetectedKey(CheckAccess);

if(CheckForWaveFiles())
{
llInstantMessage(person," No wave files in the content of this object!");
return;
}
if(AttackCHK == TRUE)
{
return;
}
else if (Elite_Playing)
{
AttackCHK = FALSE;
llWhisper(0,(string)ScriptName+" Please Wait... Stopping Sound.");
Elite_StopTheSong();
llSetTimerEvent(0.0);
}
else
AttackCHK = FALSE;
Elite_PlaySong = TRUE;
Elite_PlayTheSong();
}
timer()
{
if(!Elite_PlaySong)
{
return;
}
else if (Elite_Playing)
{
if (Elite_Sound == 1)
{
llSetTimerEvent(INTERVAL);
}
llPlaySound(llGetInventoryName(INVENTORY_SOUND,Elite_Sound),VOLUME);
if (Elite_Sound < (Elite_Track - 1) )
{
llPreloadSound(llGetInventoryName(INVENTORY_SOUND,Elite_Sound+1));
}
Elite_Sound++;
if (Elite_Sound >= Elite_Track )
{
llSetTimerEvent(INTERVAL + 5.0);
Elite_Playing = 0;
llSetTimerEvent(0.0);
Elite_PlaySong = FALSE;
llResetScript();
}
}
}
}


Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-07-2007 00:44
The other way is to use the Media streaming functionality. This was changed to allow non streaming use, i.e. just point at a file.
Mordigant Recreant
Registered User
Join date: 18 Jan 2007
Posts: 19
02-07-2007 06:46
From: Newgate Ludd
The other way is to use the Media streaming functionality. This was changed to allow non streaming use, i.e. just point at a file.


How do I set up this option?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-07-2007 07:46
From: Mordigant Recreant
How do I set up this option?



Upload the file to your server, then point the parcel media url at it to play it once.
You will ideally need to know the length of the file, or have it remove and then reselect the url each time you touch it.

This SHOULD work :-

CODE

string strURL = "http://myServer/MyMusicFile.mp3";

default
{
touch_start(integer total_number)
{
llSetParcelMusicURL("");
llSleep(0.1);
llSetParcelMusicURL(strURL);
}
}
Mordigant Recreant
Registered User
Join date: 18 Jan 2007
Posts: 19
02-07-2007 08:42
I'm not dealing with a parcel, I'm making an object. Can I still stream?