Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Control iTunes from within SL

Jarod Godel
Utilitarian
Join date: 6 Nov 2003
Posts: 729
03-28-2006 19:34
I need to make one disclaimer up front: this code works, but just barely. I'm throwing it out, as always, as a proof of concept thing more than anything else. If someone out there wants to take this, fix it up, and become the next Linden millionaire, have at it. The second uBrowser gets integrated, this is outmoded. Okay...

Step One:
Create a basic widget-like interface. I recommend something simple, but that's just me. That interface is five prims, all linked together, with the back prim as the root prim.

Step Two:
In the four, not-root prims, place the following LSL code. The only difference in the code is this block of code is the third argument (the string) in llMessageLinked. The four strings will need to be: Back, Next, Stop, and Play.

CODE

default
{
state_entry()
{

}

touch_start(integer total_number)
{
llMessageLinked(LINK_ROOT, 0, "Back", NULL_KEY);
}
}


Step Three:
In the root prim, place the following LSL code -- I don't think anything needs to be changed:

CODE

// Global Variables
string command = "Play";
string gChannel = "";

default
{
state_entry()
{
llOpenRemoteDataChannel();
llSetText("Ready", <0,255,0>, 3.0);
llSay(0, "primTuner Online!");
}

link_message(integer sender_number, integer number, string message, key id)
{
command = message;
}

remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval)
{
if (type == REMOTE_DATA_CHANNEL)
{
gChannel = channel;
llSay(0, gChannel);
}

else if (type == REMOTE_DATA_REQUEST)
{
if (ival == 100)
{
llRemoteDataReply(channel, message_id, command, 101);
}

else if (ival == 200)
{
llRemoteDataReply(channel, message_id, "Ok", 201);
llSetText(sval, <0,255,0>, 3.0);
if (command != "Play" && command != "Stop")
{
command = "Play";
}
}
}
}

state_exit()
{
llCloseRemoteDataChannel(gChannel);
}
}


Step Four:
Launch iTunes on your computer.

Step Five:
Copy and paste the channel said by your script into the following Python code (the variable "channel" needs to hold the channel key), then execute the program:

CODE

#!/usr/bin/env python

from xmlrpclib import ServerProxy
import win32com.client

iTunes = win32com.client.gencache.EnsureDispatch("iTunes.Application")
iTunes.LibrarySource.Playlists.ItemByName('Library').PlayFirstTrack()

def llRemoteData(Channel, Int, String):
client = ServerProxy("http://xmlrpc.secondlife.com/cgi-bin/xmlrpc.cgi")
return client.llRemoteData({"Channel" : Channel, "IntValue" : Int, "StringValue" : String})

channel = "d8548c03-6a8d-7158-011b-0990f8aba45f"
Int = 100

while (1):
cntr = 0
if (Int == 100):
x = llRemoteData(channel, Int, "")
if (x["StringValue"] == "Play"):
iTunes.Play()
elif (x["StringValue"] == "Next"):
iTunes.NextTrack()
elif (x["StringValue"] == "Back"):
iTunes.PreviousTrack()
else:
iTunes.Stop()
Int = 200
else:
song = iTunes.CurrentTrack.Name + "\n(" + iTunes.CurrentTrack.Artist + ")"
x = llRemoteData(channel, Int, song)
Int = 100

while(cntr < 200000):
cntr = cntr + 1


With all of this running, you should be able to control iTunes via the prim interface. You can Play songs, Stop the songs, skip to the Next, and move Back to the previous song in your main, "Library" playlist.

A couple of notes: this has only been tested on Windows XP using Python 2.4, but I know the iTunes COM interfaces work as far back as Python 2.3. Also, you will need to allow the Python code to access the Internet, as it is communicating every two seconds with the SL XML-RPC gateway. Also, you will need to change the "channel" value whenever the prim interface is restarted.
_____________________
"All designers in SL need to be aware of the fact that there are now quite simple methods of complete texture theft in SL that are impossible to stop..." - Cristiano Midnight

Ad aspera per intelligentem prohibitus.
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
03-28-2006 20:04
/54/78/96794/1.html
_____________________
i've got nothing. ;)
sounds Turner
Registered User
Join date: 13 Sep 2005
Posts: 160
Reply..
04-24-2006 04:29
Hey,

Is this something you could use anywhere in sl, when ubrowser is implemented?
And can all other users hear what you're listening to.. whereever you use it?

nice script