Change font size
It is currently Tue Jul 17, 2018 11:38 pm

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 9 posts ]
Author Message
 Post subject: YouTube Player
PostPosted: Sat Mar 21, 2009 11:00 pm 
User avatar

Joined: Sat Mar 21, 2009 10:05 pm
Posts: 7
Location: Quebec City, Quebec, Canada
As used in my region. (Extrems' Corner)

{L_CODE}:

//
// YouTube Player (Version 1.0.0)
// By Extrems for OSGrid simulator.
//  http://www.extremscorner.co.cc/
//
// This script is licensed under:
// Creative Commons Attribution-Share Alike 3.0 Unported
//  http://creativecommons.org/licenses/by-sa/3.0/
//
// Documentation:
//  http://www.extremscorner.co.cc/?page=content&name=docs/youtube
//


// * Constants
integer INTEGER_MAX = 2147483647;

integer LEVEL_NOTICE = 0x00;
integer LEVEL_WARNING = 0x01;
integer LEVEL_ERROR = 0x02;

float fltPassTimer = 60.0;
float fltPoolTimer = 5.0;

string strYtBase = "http://www.youtube.com/watch?v=";
string strAddress = "http://backend.cgetechnologies.co.cc:8080/directvid.php";
list lstHttpParams = [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"];


// * Variables
string strLastDesc;
key keyRequest;

key keyThumbnail;
string strVideoID;
string strContainer;
integer intMaxWidth;

integer intUnset;    // Part of osSetDynamicTextureURL workaround.


// * Functions
//  DebugSay: Just because I can.
DebugSay(string strMessage, integer intLevel)
{
    string strOutput = "(";
   
    if (intLevel == LEVEL_WARNING)
    {
        strOutput += "Warning";
    }
    else if (intLevel == LEVEL_ERROR)
    {
        strOutput += "Error";
    }
    else
    {
        strOutput += "Notice";
    }
   
    strOutput += ") " + strMessage;
    llOwnerSay(strOutput);
}

//  Refresh:
Refresh()
{
    if (strLastDesc)
    {
        integer intDotIndex = llSubStringIndex(strLastDesc, ".");
       
        if (intDotIndex >= 0)
        {
            strVideoID = llGetSubString(strLastDesc, 0, intDotIndex - 1);
           
            string strExtension = llGetSubString(strLastDesc, intDotIndex + 1, -1);
            integer intSlashIndex = llSubStringIndex(strExtension, "/");
           
            if (intSlashIndex >= 0)
            {
                strContainer = llGetSubString(strExtension, 0, intSlashIndex - 1);
                intMaxWidth = (integer)llGetSubString(strExtension, intSlashIndex + 1, -1);
            }
            else
            {
                strContainer = strExtension;
            }
           
            // Remove mentions of FLV if you're on Linux and got a plug-in for GStreamer.
            if (!strContainer || (strContainer == "flv"))
            {
                if (strContainer == "flv")
                {
                    DebugSay("The Flash Video container format is not supported by QuickTime.", LEVEL_WARNING);
                }
               
                DebugSay("Falling back to MPEG-4 Part 14.", LEVEL_NOTICE);
                strContainer = "mp4";   
            }
           
            // Who wrote this function?!
            // Seriously, what the fuck.
            keyThumbnail = osSetDynamicTextureURL("", "image", "http://i.ytimg.com/vi/" + strVideoID + "/default.jpg", "", INTEGER_MAX);
            intUnset = FALSE;
           
            if (keyThumbnail)
            {
                state active;
            }
            else
            {
                DebugSay("Couldn't load thumbnail image, video ID may be invalid.", LEVEL_ERROR);
            }
        }
    }
    else
    {
        DebugSay("Object's description is empty.", LEVEL_ERROR);
    }
   
    state idle;
}


// * States
//  default:
default
{
    state_entry()
    {
        strLastDesc = llGetObjectDesc();
        Refresh();
    }
   
    on_rez(integer start_param)
    {
        llResetScript();
    }
}

//  active:
state active
{
    state_entry()
    {
        string strBody;
        strBody += "action=" + "verify";
        strBody += "&url=" + llEscapeURL(strYtBase + strVideoID);
       
        keyRequest = llHTTPRequest(strAddress, lstHttpParams, strBody);
        llSetTimerEvent(fltPassTimer);
    }
   
    touch_start(integer num_detected)
    {
        llSetPrimitiveParams([PRIM_TEXTURE, ALL_SIDES, keyThumbnail, <1.0, 1.0, 0.0>, <0.0, 0.0, 0.0>, 0.0, PRIM_FULLBRIGHT, ALL_SIDES, TRUE]);
        intUnset = TRUE;
       
        llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_STOP, PARCEL_MEDIA_COMMAND_UNLOAD]);
        llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_TEXTURE, keyThumbnail]);
       
        string strMediaURL = strAddress + "?";
        strMediaURL += "action=" + "play";
        strMediaURL += "&containers=" + strContainer;
        if (intMaxWidth) { strMediaURL += "&width=" + (string)intMaxWidth; }
        strMediaURL += "&url=" + llEscapeURL(strYtBase + strVideoID);
       
        llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_URL, strMediaURL]);
        llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_PLAY]);
    }
   
    on_rez(integer start_param)
    {
        llResetScript();
    }
   
    timer()
    {
        string strCurDesc = llGetObjectDesc();
       
        if (strLastDesc != strCurDesc)
        {
            llResetScript();
        }
       
        llSensor("", NULL_KEY, AGENT, 96.0, TWO_PI);
    }
   
    sensor(integer num_detected)
    {
    }
   
    no_sensor()
    {
        if (intUnset)
        {
            keyThumbnail = osSetDynamicTextureURL("", "image", "http://i.ytimg.com/vi/" + strVideoID + "/default.jpg", "", INTEGER_MAX);
            intUnset = FALSE;
        }
    }
   
    http_response(key request_id, integer status, list metadata, string body)
    {
        if (request_id == keyRequest)
        {
            if (llSubStringIndex(llGetSubString(body, 0, 30), "<") >= 0)
            {
                DebugSay("The DirectVid backend appears to be broken.", LEVEL_WARNING);
            }
            else if (llSubStringIndex(body, "http://") < 0)
            {
                DebugSay("Server returned: " + body, LEVEL_NOTICE);
            }
        }
    }
}

//  idle:
state idle
{
    state_entry()
    {
        llSetTimerEvent(fltPoolTimer);
    }
   
    on_rez(integer start_param)
    {
        llResetScript();
    }
   
    timer()
    {
        string strCurDesc = llGetObjectDesc();
       
        if (strLastDesc != strCurDesc)
        {
            llResetScript();
        }
    }
}


Object's description format: (id).(container)[/(width)]
Use 3gp (mobile) if you have a weak CPU.

Always define the maximum width if you're using mp4 and viewing videos available in HD. (unless you got a beefy computer)


Top
 Profile  
 
 Post subject: Re: YouTube Player
PostPosted: Thu Mar 26, 2009 8:37 pm 

Joined: Thu Mar 26, 2009 8:33 pm
Posts: 2
Hi,
Im reletivly new to Opensim, i tryed to get this working in my standalone region but i added the script to a box and added the youtube url in but got nothing, there was no compile errors but nothing happened. Are you able to shed any light im noob with open sim atm so id appreciate any help.


Top
 Profile  
 
 Post subject: Re: YouTube Player
PostPosted: Fri Mar 27, 2009 2:19 pm 
User avatar

Joined: Sat Mar 21, 2009 10:05 pm
Posts: 7
Location: Quebec City, Quebec, Canada
http://www.youtube.com/watch?v=(id)

http://www.youtube.com/watch?v=MVP4cVLPzV4
MVP4cVLPzV4.mp4/640


Top
 Profile  
 
 Post subject: Re: YouTube Player
PostPosted: Sat Mar 28, 2009 7:02 am 
Furious Typer
User avatar

Joined: Sun Aug 31, 2008 4:34 pm
Posts: 107
Very kewl script,

Now we need a YouTube search in chat line.
like:/1 keyword or youtube videos in memory or myplaylist notecard.

else I will need 100 screens or more if I wanna be a VJ ;)

works on mine too
Lz-x7jn2hws.mp4/640


Top
 Profile  
 
 Post subject: Re: YouTube Player
PostPosted: Sat Mar 28, 2009 5:51 pm 

Joined: Thu Mar 26, 2009 8:33 pm
Posts: 2
Hey Guys, i belive i got the script correct but now returns a bunch of errors on compile. Does the script engine matter? im using the default ive only changed the physics engine and pritty much nothing else in the ini file.


Top
 Profile  
 
 Post subject: Re: YouTube Player
PostPosted: Sat Mar 28, 2009 7:11 pm 
Furious Typer
User avatar

Joined: Sun Aug 31, 2008 4:34 pm
Posts: 107
I think.. I am blonde .. I just dropped it in a prim and pasted into the description line the key and parameters like we have shown above. ( Lz-x7jn2hws.mp4/640 )
My test region is default XEngine and true on X and Dot. After your mod don't forget to do a recompile in tools.
If you still have issues, I can drop my asset for you. Hmm that sounds kinky ;)

A working perm copy is on the deck at Sailors Vista, enjoy


Top
 Profile  
 
 Post subject: Re: YouTube Player
PostPosted: Sun May 24, 2009 11:08 am 

Joined: Wed May 06, 2009 7:26 am
Posts: 28
I have tried everything to get this working

But it wont work i get a grey screen on the box.


Top
 Profile  
 
 Post subject: Re: YouTube Player
PostPosted: Wed Aug 11, 2010 1:09 am 

Joined: Wed Aug 11, 2010 1:05 am
Posts: 1
When I try running this on a prim. I receive (Notice) Server returned: Unable to find required data.
Here is the video link
http://www.youtube.com/watch?v=0MP_G6arpVI and in the description I have tried 0MP_G6arpVI , 0MP_G6arpVI.mp4 , 0MP_G6arpVI.mp4/640

Any thoughts?

One added note. It does show the preview image just fine.


Top
 Profile  
 
 Post subject: Re: YouTube Player
PostPosted: Wed Aug 11, 2010 9:26 am 
Site Admin
User avatar

Joined: Sat Feb 02, 2008 5:27 pm
Posts: 843
Youtube no longer allows you to stream video, no youtube scripts work anymore.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 9 posts ]


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
610nm Style by Daniel St. Jules of Gamexe.net