You are currently browsing the tag archive for the ‘media’ tag.

A Little History

Second Life has long had a system for displaying video on a prim. This is the parcel-media system, whereby you can supply a URL for a video feed, and the video will be displayed on an assigned texture (if you have never seen this before, the set-up for it is on the last tab of the About Land dialog). Its main restriction has been (and still is) that only one video can be displayed on each parcel of land. You can have any number of prims displaying the video, but they will all display the same video.

It has always been possible to display output from a web-site to the parcel media stream, although it was never easy. If you are interested, it involves creating a CGI script on a web-site to generate an image. By then pointing the parcel-media URL at this script, the image will be displayed on any prim which uses the parcel-media texture.

I experimented with this myself a little while ago, and got a system up and running which would display text which was ‘chatted’ by an avatar. I had ideas about creating some sort of live broadcast system. Unfortunately, the Quicktime vulnerability then appeared, and for some time anyone with any sense kept parcel-media switched off. I stopped experimenting at that point, and didn’t go back to it even after the vulnerability was fixed.

Recent Changes

The more recent versions of Second Life include the ability to directly display a web-page via the parcel-media. Point the parcel-media URL at a web-page, and the page will be displayed on the parcel-media texture.

This brings us a step closer to the long-promised HTML-on-a-prim, but we aren’t quite there yet. For a start, this system only applies to parcel-media, and hence suffers from the same restrictions that parcel-media suffers from. There are also some quirks in the way in which the web-pages are displayed.

The main problem that I have found is that the pages seem to rendered at a fixed size (it looks to be something like a 1024 x 1024 area). If the webpage is too large to fit this, scroll-bars will appear. Of course, because the page is essentially just displayed as an image, these scroll-bars are inactive in Second Life. It also means that you have to display the page on a fairly sizeable prim in order for a normal web-page to be readable. It would have been nice to have the ability to display only part of the web-page, with it sizing to fit the prim.

Implementing a Broadcaster

So much for the background. Now, how can we make use of this? Obviously, we can just display a web-page, but there other things that can be done, such as creating genuinely active text. That’s what I want to demonstrate in this post. It is going to be rather simplistic and limited, but it should be quite easy to extend the basic idea into something more sophisticated and useful.

To make particular example work, you will need a website that handles PHP, and that you can upload files to. You will also need to own or rent a parcel of land that you can change the parcel-media on (obviously!).

Let’s start with the PHP script (if you are more familiar with other web-page scripting languages, it should not be difficult to adapt this script):

<html>
<head></head>
<style>body { font-size: 64pt; font-family: Verdana, sans-serif }</style>
<body>
<?php

// Get the text to display.
$contents = stripslashes($_GET&#91;"contents"&#93;);

// Only works with PHP compiled as an Apache module.
$headers = apache_request_headers();
$ownerKey = $headers&#91;"X-SecondLife-Owner-Key"&#93;;

// Output the text.
echo("<p>".$contents."</p>\n");

?>
</body>
</html>

This script expects to be passed a ‘comments’ parameter containing the text to be displayed. For example, assuming you have saved the script as broadcast.php, the following would be used to call the script:

broadcast.php?contents=This%20is%20a%20test.

This would display a web-page with the line “This is a test.”.

A couple of other points: the code above includes a line to read the owner key, but doesn’t make any use of it. In a real situation you would probably want to use this as the basis for some kind of security (remember that anyone with a browser can call this script!). There are also a number of other headers which are available — see the LSL Wiki for more information about them.

Also note that I have set the font-size to a rather large 64 points! This is so that the line of text will show up at a reasonable size on our display.

Now for the Second Life side.

For this example we will set up a script that will listen on a specified channel, and will use our web-script to display anything which is chatted on that channel. We will also set up a timer that will automatically clear the text and replace it with a default after 30 seconds.

In this example I am using a script on my own website — you should replace the URL with the appropriate path for your own site. You can make use of the script on my website if you want to just try things out, but it will display my own logo, and is not guaranteed to stay on the website for long, as it is only a test.

string text;
string baseUrl = "http://ejournal.cyberias.net/broadcast.php?contents=";
integer anyoneCanUse = TRUE;
key avatar;
integer handle;
integer onChannel = 1234;

init()
{
  text = llEscapeURL("Chat some text on channel /" + (string)onChannel);
  string url = baseUrl + text;
  llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_URL, url, PARCEL_MEDIA_COMMAND_PLAY, PARCEL_MEDIA_COMMAND_LOOP]);
}

send()
{
  string url = baseUrl + text;
  llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_URL, url]);
}

default
{
  state_entry()
  {
    llSetTimerEvent(30.0);
    handle = llListen(onChannel, "", avatar, "");
  }

  listen(integer channel, string name, key id, string message)
  {
    if (channel == onChannel)
    {
      llSetTimerEvent(0.0);
      text = llEscapeURL(message);
      send();
      llSetTimerEvent(30.0);
    }
  }

  timer()
  {
    text = llEscapeURL("Chat some text on channel /" + (string)onChannel);
    send();
  }

  state_exit()
  {
    llListenRemove(handle);
    llSetTimerEvent(0.0);
  }
}

Create a prim, and apply your parcel-media texture to one face. Create a script in the prim, and replace the default contents with the above code.

Anyone who stands near the prim and chats on the specified channel will have the chat displayed on the prim (provided, of course, that they have video switched on).

Here is my own test broadcaster in action:

Text on a Prim!