Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

FreeView - Picture Viewer & Video Control

CrystalShard Foo
1+1=10
Join date: 6 Feb 2004
Posts: 682
04-02-2005 16:34
---------------------------------------------------------
IMPORTANT NOTE!

This is an OLD version of FreeView! This thread is out-dated. For the latest version, please check this thread: /15/d3/53495/1.html
---------------------------------------------------------


So SL 1.6 is finally here, and with it, streaming video.

To help celebrate the occasion, I'd like to give the following script to the community:

FreeView is an all-in-one video controller and picture viewer. It supports all the basics in both modes, includes an auto-parcel configuration function, and a comfy advance bookmarks function that works off a notecard as a source.

The bookmarks notecard is required to be called "bookmarks" by default. To add a URL, just add the name, followed by the URL, with a | char as a separator. Please only add one URL per line, and try to avoid putting blank lines without text. (The script can handle such lines, but its still recommended not to). For example:

name|url
name|url
name|url

... and so on.

If you find a bug in this script, feel free to fix and post. But please keep the credit list intact. You may add your own name to the credits on scripts that you modify.

Those of you who'd like to get it in-world instead, you can buy a copy for 1L$ at Script-Foo! at Apukohai 165,11.

Here's the script. Happy viewing!
CrystalShard Foo
1+1=10
Join date: 6 Feb 2004
Posts: 682
04-02-2005 16:37
CODE

//FreeView 1.0 - By CrystalShard Foo
//Multifunctional Picture viewer and Video control script
//This script is distributed for free and must stay that way. DO NOT SELL THIS SCRIPT UNDER ANY CIRCUMSTANCE.

//Feel free to modify this script and post your improvement. Leave the credits intact but feel free to add your name at its bottom.


//Constants
float PICTURE_ROTATION_TIMER = 30; //In whole seconds

integer DISPLAY_ON_SIDE = ALL_SIDES; //Change this to change where the image will be displayed

key VIDEO_DEFAULT = "6e0f05ad-1809-4edc-df29-fae3d2a6c9b8"; //Test pattern - Used as default video texture when one is missing in parcel media
key BLANK = "5748decc-f629-461c-9a36-a35a221fe21f"; //Blank texture - Used when there are no textures to display in Picture mode
string NOTECARD = "bookmarks"; //Used to host URL bookmarks for video streams


integer mode = 0; //Freeview mode.
//Mode 0 - Power off
//Mode 1 - Picture viewer
//Mode 2 - Video

integer listenHandle = -1; //Dialog menu listen handler
integer listenurl = -1; //listen handler for channel 1 for when a URL is being added
integer listenTimer = -1; //Timer variable for removing all listeners after 2 minutes of listener inactivity
integer numberofnotecardlines = 0; //Stores the current number of detected notecard lines.
integer notecardline = 0; //Current notecard line

integer loop_image = FALSE; //Are we looping pictures with a timer? (picture mode)
integer current_texture = 0; //Current texture number in inventory being displayed (picture mode)
integer chan; //llDialog listen channel
integer notecardcheck = 0;
key video_texture; //Currently used video display texture for parcel media stream

key tempuser; //Temp key storge variable
string tempurl; //Temp string storge variable

pictures() //Change mode to Picture Viewer
{
//Change prim to Light material while coloring face 0 black to prevent light-lag generation.
llSetPrimitiveParams([PRIM_BUMP_SHINY,DISPLAY_ON_SIDE,PRIM_SHINY_NONE,PRIM_BUMP_NONE,PRIM_COLOR,DISPLAY_ON_SIDE,<1,1,1>,1.0,PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llSetColor(<0,0,0>,0);

//Initilize variables
current_texture = 0;

//Set to first texture if available
integer check = llGetInventoryNumber(INVENTORY_TEXTURE);
if(check > 0)
display_texture(check);
else
{
llSetObjectDesc("No pictures found.");
llSetTexture(BLANK,DISPLAY_ON_SIDE);
}
}

video() //Change mode to Video
{
llSetObjectDesc("Video mode: Stopped");
if(finditem(NOTECARD) != -1)
tempuser = llGetNumberOfNotecardLines(NOTECARD);
video_texture = llList2Key(llParcelMediaQuery([PARCEL_MEDIA_COMMAND_TEXTURE]),0);
if(video_texture == NULL_KEY)
{
video_texture = VIDEO_DEFAULT;
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_TEXTURE,VIDEO_DEFAULT]);
llSay(0,"No parcel media texture found. Setting texture to default: "+(string)VIDEO_DEFAULT);
if(llGetLandOwnerAt(llGetPos()) != llGetOwner())
llSay(0,"Error: Cannot modify parcel media settings. "+llGetObjectName()+" is not owned by parcel owner.");
}
//Change prim to Light material while coloring face 0 black to prevent light-lag generation.
llSetPrimitiveParams([PRIM_BUMP_SHINY,DISPLAY_ON_SIDE,PRIM_SHINY_NONE,PRIM_BUMP_NONE,PRIM_COLOR,DISPLAY_ON_SIDE,<1,1,1>,1.0,PRIM_MATERIAL,PRIM_MATERIAL_LIGHT,PRIM_TEXTURE,DISPLAY_ON_SIDE,video_texture,<1,1,0>,<0,0,0>,TWO_PI]);
llSetColor(<0,0,0>,0);
}

off()
{
llSetObjectDesc("Click to power on.");
llSetPrimitiveParams([PRIM_BUMP_SHINY,DISPLAY_ON_SIDE,PRIM_SHINY_LOW,PRIM_BUMP_NONE,PRIM_COLOR,DISPLAY_ON_SIDE,<0.1,0.1,0.1>,1.0,PRIM_MATERIAL,PRIM_MATERIAL_PLASTIC,PRIM_TEXTURE,DISPLAY_ON_SIDE,BLANK,<1,1,0>,<0,0,0>,TWO_PI]);
}

integer finditem(string name) //Finds and returns an item's inventory number
{
integer i;
for(i=0;i<llGetInventoryNumber(INVENTORY_NOTECARD);i++)
if(llGetInventoryName(INVENTORY_NOTECARD,i) == NOTECARD)
return i;
return -1;
}

seturl(string url, key id) //Set parcel media URL
{
string oldurl = llList2String(llParcelMediaQuery([PARCEL_MEDIA_COMMAND_URL]),0);
if(oldurl != "")
llOwnerSay("Setting new media URL. The old URL was: "+oldurl);
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_URL,url]);
menu(id);
llOwnerSay("New media URL set.");
}

string mediatype(string ext) //Returns a string stating the filetype of a file based on file extension
{
ext = llToLower(ext);
if(ext == "swf")
return "Flash";
if(ext == "mov" || ext == "avi" || ext == "mpg" || ext == "mpeg" || ext == "smil")
return "Video";
if(ext == "jpg" || ext == "mpeg" || ext == "gif" || ext == "png" || ext == "pict" || ext == "tga" || ext == "tiff" || ext == "sgi" || ext == "bmp")
return "Image";
if(ext == "txt")
return "Text";
return "Unknown";
}

browse(key id) //Image browser function for picture viewer mode
{
integer check = llGetInventoryNumber(INVENTORY_TEXTURE);
string header;
if(check > 0)
header = "("+(string)(current_texture+1)+"/"+(string)check+") "+llGetInventoryName(INVENTORY_TEXTURE,current_texture);
else
header = "No pictures found.";
llDialog(id,"** Monitor Control **\n Picture Viewer mode\n- Image browser\n- "+header,["Back","Next","Menu"],chan);
extendtimer();
}

extendtimer() //Add another 2 minute to the Listen Removal timer (use when a Listen event is triggered)
{
if(listenHandle == -1)
listenHandle = llListen(chan,"","","");
listenTimer = (integer)llGetTime() + 120;
if(loop_image == FALSE)
llSetTimerEvent(45);
}

config(key id) //Configuration menu
{
extendtimer();
llDialog(id,"Current media URL:\n"+llList2String(llParcelMediaQuery([PARCEL_MEDIA_COMMAND_URL]),0),["Set URL","Align ON","Align OFF","Menu"],chan);
}

menu(key id) //Dialog menus for all 3 modes
{
list buttons = [];
string title = "** Monitor control **";

extendtimer();

if(mode != 0)
{
if(mode == 1) //Pictures menu
{
title+="\n Picture Viewer mode";
// buttons+=["Back","Next"];
buttons+=["Browse"];
if(loop_image == FALSE)
buttons+=["Loop"];
else
buttons+=["Unloop"];
buttons+=["Video","Power off"];
}
else //Video menu
{
title+="\n Video display mode";
buttons+=["Configure","Bookmarks","Power off","Pause","Unload","Pictures","Play","Stop","Loop"];
}
}
else
buttons += ["Pictures","Video"];

llDialog(id,title,buttons,chan);
}

display_texture(integer check) //Display texture and set name in description (picture mode)
{ //"Check" holds the number of textures in contents. The function uses "current_texture" to display.
string name = llGetInventoryName(INVENTORY_TEXTURE,current_texture);
llSetTexture(name,DISPLAY_ON_SIDE);
llSetObjectDesc("Showing picture: "+name+" ("+(string)(current_texture+1)+"/"+(string)check+")");
}


next() //Change to next texture (picture mode)
{ //This function is used twice - by the menu and timer. Therefor, it is a dedicated function.
current_texture++;
integer check = llGetInventoryNumber(INVENTORY_TEXTURE);
if(check == 0)
{
llSetTexture(BLANK,DISPLAY_ON_SIDE);
current_texture = 0;
llSetObjectDesc("No pictures found.");
return;
}
if(check == current_texture)
current_texture = 0;

display_texture(check);
return;
}

default
{
state_entry()
{
chan = (integer)llFrand(1000) + 1000; //Pick a random listen channel for the listener
if(PICTURE_ROTATION_TIMER <= 0) //Ensure the value is no less or equal 0
PICTURE_ROTATION_TIMER = 1;
llListenRemove(listenHandle);
listenHandle = -1;
off();
}

on_rez(integer i)
{
llResetScript();
}

touch_start(integer total_number)
{
//-------------------------------------------------------------------------------
//Listen only to owner or group member. Edit this code to change access controls.
if(llDetectedKey(0) != llGetOwner() && llDetectedGroup(0) == FALSE)
return;
//-------------------------------------------------------------------------------

menu(llDetectedKey(0));
}

changed(integer change)
{
if(change == CHANGED_INVENTORY) //If inventory change
if(mode == 1) //If picture mode
{
integer check = llGetInventoryNumber(INVENTORY_TEXTURE);
if(check != 0)
{
current_texture = 0;
display_texture(check);
}
else
{
llSetTexture(BLANK,DISPLAY_ON_SIDE);
llSetObjectDesc("No pictures found.");
}
}
else
if(mode == 2) //If video mode
if(finditem(NOTECARD) != -1) //And bookmarks notecard present
tempuser = llGetNumberOfNotecardLines(NOTECARD); //Reload number of lines
}

listen(integer channel, string name, key id, string message)
{
if(message == "Pictures")
{
if(mode == 2)
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_STOP]);
pictures();
mode = 1;
menu(id);
return;
}
if(message == "Video")
{
video();
mode = 2;
menu(id);
return;
}
if(message == "Power off")
{
if(mode == 2)
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_UNLOAD]);
off();
mode = 0;
return;
}
if(mode == 1)
{
if(message == "Browse")
{
loop_image = FALSE;
browse(id);
return;
}
if(message == "Next")
{
extendtimer();
next();
browse(id);
}
if(message == "Back")
{
extendtimer();
current_texture--;
integer check = llGetInventoryNumber(INVENTORY_TEXTURE);
if(check == 0)
{
llSetTexture(BLANK,DISPLAY_ON_SIDE);
current_texture = 0;
llSetObjectDesc("No pictures found.");
return;
}
if(current_texture < 0)
current_texture = check - 1;

display_texture(check);

browse(id);
return;
}
if(message == "Menu")
{
menu(id);
return;
}
if(message == "Loop")
{
llSetTimerEvent(PICTURE_ROTATION_TIMER);
loop_image = TRUE;
llOwnerSay("Picture will change every "+(string)PICTURE_ROTATION_TIMER+" seconds.");
return;
}
if(message == "Unloop")
{
loop_image = FALSE;
llOwnerSay("Picture loop disabled.");
return;
}
}
if(mode == 2)
{
string header = "Video mode: ";
if(message == "<< Prev")
{
notecardline--;
if(notecardline < 0)
notecardline = numberofnotecardlines - 1;
tempuser = id;
llGetNotecardLine(NOTECARD,notecardline);
return;
}
if(message == "Next >>")
{
notecardline++;
if(notecardline >= numberofnotecardlines)
notecardline = 0;
tempuser = id;
llGetNotecardLine(NOTECARD,notecardline);
return;
}
if(message == "Use")
{
if(tempurl == "** No URL specified! **")
tempurl = "";
seturl(tempurl,id);
return;
}

if(message == "Menu")
{
menu(id);
return;
}
if(message == "Configure")
{
config(id);
return;
}
if(message == "Bookmarks")
{
if(notecardcheck != -1)
{
llDialog(id,"Error: No valid bookmark data found in notecard '"+NOTECARD+"'.",["Menu"],chan);
return;
}
if(finditem(NOTECARD) != -1)
{
tempuser = id;
if(numberofnotecardlines < notecardline)
notecardline = 0;
llGetNotecardLine(NOTECARD,notecardline);
}
else
llDialog(id,"Error: No notecard named "+NOTECARD+" found in contents.",["Menu"],chan);
return;
}

if(llGetLandOwnerAt(llGetPos()) != llGetOwner()) //If we do not have permissions to actually do the following functions
{
llSay(0,"Error: Cannot modify parcel media settings. "+llGetObjectName()+" is not owned by parcel owner.");
menu(id);
return; //Abort
}

if(listenurl != -1 && channel == 1) //Incoming data from "Set URL" command (user spoke on channel 1)
{
llListenRemove(listenurl);
listenurl = -1;
seturl(message,id);
}
if(message == "Play")
{
llSetObjectDesc(header+"Playing");
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_PLAY]);
return;
}
if(message == "Stop")
{
llSetObjectDesc(header+"Stopped");
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_STOP]);
return;
}
if(message == "Pause")
{
llSetObjectDesc(header+"Paused");
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_PAUSE]);
return;
}
if(message == "Unload")
{
llSetObjectDesc(header+"Stopped");
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_UNLOAD]);
return;
}
if(message == "Loop")
{
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_LOOP]);
return;
}
//URL , Auto-Scale,
if(message == "Set URL")
{
llSetObjectDesc(header+"Stopped");
listenurl = llListen(1,"",id,"");
// llInstantMessage(llGetOwner(),"Please type the URL of your choice with /1 at the begining. For example, /1 www.google.com");
llDialog(id,"Please type the URL of your choice with /1 in thebegining. For example, /1 www.google.com",["Ok"],938);
return;
}
if(message == "Align ON")
{
llSetObjectDesc(header+"Stopped");
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_AUTO_ALIGN,TRUE]);
menu(id);
return;
}
if(message == "Align OFF")
{
llSetObjectDesc(header+"Stopped");
llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_AUTO_ALIGN,FALSE]);
menu(id);
return;
}
}
}

dataserver(key queryid, string data)
{
if(queryid == tempuser) //If just checking number of notecard lines
{
numberofnotecardlines = (integer)data;
notecardcheck = 0;
llGetNotecardLine(NOTECARD,notecardcheck);
return;
}
if(notecardcheck != -1)
{
if(data != EOF)
{
if(data == "")
{
notecardcheck++;
llGetNotecardLine(NOTECARD,notecardcheck);
}
else
{
notecardcheck = -1;
return;
}
}
else
return;
}

if(data == "" && notecardline < numberofnotecardlines) //If user just pressed "enter" in bookmarks, skip
{
notecardline++;
llGetNotecardLine(NOTECARD,notecardline);
return;
}

if(data == EOF)
{
notecardline = 0;
llGetNotecardLine(NOTECARD,notecardline);
return;
}
list parsed = llParseString2List(data,["|","| "," |"," | "],[]); //Ensure no blank spaces before "http://".
string name = llList2String(parsed,0);
tempurl = llList2String(parsed,1);
if(tempurl == "")
tempurl = "** No URL specified! **";

llDialog(tempuser,"Bookmarks notecard ("+(string)(notecardline+1)+"/"+(string)numberofnotecardlines+")\n"+name+" ("+mediatype(llList2String(llParseString2List(tempurl,["."],[]),-1))+")\n"+tempurl,["<< Prev","Use","Next >>","Menu"],chan);
}

timer()
{
if(llGetTime() > listenTimer) //If listener time expired...
{
llListenRemove(listenHandle); //Remove listeneres.
llListenRemove(listenurl);
listenHandle = -1;
listenurl = -1;
listenTimer = -1;
if(loop_image == FALSE || mode != 1) //If we're not looping pictures or are in picture mode at all
llSetTimerEvent(0.0); //Remove timer
}

if(loop_image == TRUE && mode == 1) //If we're looping pictures and and we're in picture mode...
next(); //Next picture
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion thread
04-02-2005 16:44
/54/59/41141/1.html
_____________________
i've got nothing. ;)