Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion: 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
Original Thread
03-28-2006 20:04
/15/75/96782/1.html
_____________________
i've got nothing. ;)
Darkland Fluffy
Registered User
Join date: 20 Jan 2006
Posts: 4
03-29-2006 12:29
Very nice.
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
03-29-2006 16:30
Damn; it doesn't work with Macintosh :D
Sandy Schnook
Official Dorkette
Join date: 31 Dec 2005
Posts: 60
Complete Python Noob
04-01-2006 21:14
I think I have been able to manage everything but allowing the Python Code to have internet access. I'm not much of a programmer and am using Python for the first time. Can anyone direct me to a code or module I can use to allow the internet access? I've been looking until I'm almost blind, and would greatly appreciate any help. I have a boatload of tunes in Itunes and would love to have my own music in world.
Jarod Godel
Utilitarian
Join date: 6 Nov 2003
Posts: 729
04-03-2006 07:58
From: Sandy Schnook
I think I have been able to manage everything but allowing the Python Code to have internet access.
That just means you need to tell your firewall to allow python.exe access the Internet.
_____________________
"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.
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-03-2006 09:56
From: Jarod Godel
That just means you need to tell your firewall to allow python.exe access the Internet.
That's just Wrong.

I mean.

The idea that your firewall would prevent your local applications from making network connections.

Scary.
Lecina Enigma
Linux Client User-x86_64
Join date: 16 Nov 2005
Posts: 32
05-11-2006 15:01
I get this error from "normal" python 2.4 :



Traceback (most recent call last):
File "C:\itunes-sl.py.txt", line 4, in -toplevel-
import win32com.client
ImportError: No module named win32com.client





Path etc is set. cans omeone help me ? :)
Joseph Cult
Registered User
Join date: 7 Jan 2006
Posts: 4
Help
07-31-2006 18:31
I run the script with the new channel in python Shell 2.4 and it just executes and no errors or anything but i try to use the Sl script to controll and it doesnt work
Joseph Cult
Registered User
Join date: 7 Jan 2006
Posts: 4
nvm-help
07-31-2006 18:39
ok...figured out last one...now i have this problem:

Traceback (most recent call last):
File "C:/Python24/SL-Itunes-test", line 4, in -toplevel-
import win32com.client
ImportError: No module named win32com.client
Goapinoa Primeau
Addict
Join date: 29 Jun 2006
Posts: 58
is this possible
08-02-2006 16:19
"I have a boatload of tunes in Itunes and would love to have my own music in world."

I hav no idea what a python is besides akind of snake (i think) but if its really possible to do this i'll start my education immediately. Is it possible to pipe your itunes content into secondlife or are you discussing controlling what itunes is doing via secondlife scripted items. I can see how it ought not be difficult to have software 'listening' to secondlife and passing instructions to itunes to deal with locally. but surely you can't have itunes send its music directly in to secondlife??? Can you?
jrrdraco Oe
Insanity Fair
Join date: 28 Oct 2005
Posts: 372
08-02-2006 17:56
It will not be a good thing, if everyone decided to start streaming ones own media, everyone would die by lag and woudn´t be able to listen to the ambient sound, it would be more like walking in the busy metropolis. Best thing is to contact the local area manager and ask to switch stream.
_____________________
--
Linux Specs: http://www.immerdrauf.com/jrrhack/specs.txt
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
08-02-2006 18:22
From: Goapinoa Primeau
but surely you can't have itunes send its music directly in to secondlife??? Can you?
No.
AnkhMorpork Salsman
Registered User
Join date: 18 Apr 2006
Posts: 4
09-08-2006 01:49
From: Goapinoa Primeau
but surely you can't have itunes send its music directly in to secondlife??? Can you?



Unless you make an automated program to cut up a song into 10 second strips, connect to SL servers like a normal client would using packet injection (see libsecondlife for more details), upload all of the 10 second strips and put them into a jukebox object to play it.