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.