Jump to content

Synced TV.


Quistess Alpha
 Share

You are about to reply to a thread that has been inactive for 462 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

A basic example of a TV that should stay relatively in sync between everyone watching, as long as they use the provided controls on the object and ~not the media controls on the media face itself.

The script as written only plays one movie/video (specified in the script), and expects named links to be used as control inputs. (different faces would be more efficient for land impact, but would make setting up and using the example from the script alone more confusing) There are plenty of things that could be added or improved, this is mostly just a minimum working example for demonstration.

string gMediaFile = "https://ia800204.us.archive.org/25/items/Maniac1934/Maniac1934_512kb.mp4";
integer gFace = 2;

integer gTimeStart;
integer gTimePause;
string gsURL;
key ghRequestURL;

string gXHTML()
{   return 
"<!DOCTYPE xhtml>
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<script type=\"text/javascript\">
    function setTime(){ 
      var vid = document.getElementById(\"vid\");
      vid.currentTime=\""+(string)(llGetUnixTime()-gTimeStart)+"\"
      //vid.requestFullscreen + browser specific variations don't seem to work.
    }
</script>
<style>
body {background-color:black;}
</style>
<body onload=\"setTime()\">
<video
   id=\"vid\"
   controls=\"\"
   src=\""+gMediaFile+"\"
   autoplay=\"\"
   style=\"width:100%;height:100%;\"
   />
</body></html>";
}
integer gIncrement;
set_media()
{ 
    string s = (string)((++gIncrement)&7);
    llSetLinkMedia(LINK_THIS,gFace,
    [   PRIM_MEDIA_HOME_URL, gsURL+"/home"+s,
        PRIM_MEDIA_CURRENT_URL, gsURL+"/home"+s,
        PRIM_MEDIA_AUTO_PLAY, TRUE,
        PRIM_MEDIA_PERMS_CONTROL, PRIM_MEDIA_PERM_NONE, // don't show nav-bar.
        PRIM_MEDIA_PERMS_INTERACT, PRIM_MEDIA_PERM_NONE
    ]);
}
default
{   state_entry()
    {   ghRequestURL = llRequestURL();
        gTimeStart = llGetUnixTime()+5;
        llOwnerSay("debug");
    }
    changed(integer c)
    {   if(c&(CHANGED_REGION_START|CHANGED_REGION))
        {   llReleaseURL(gsURL);
            ghRequestURL = llRequestURL();
        }
    }
    http_request(key ID, string Method, string Body)
    {   if(ID==ghRequestURL)
        {   gsURL=Body;
            llSay(0,gsURL);
            set_media();
        }else
        {   llSetContentType(ID,CONTENT_TYPE_XHTML);
            llHTTPResponse(ID,200,gXHTML());
        }
    }
    touch_start(integer total_number)
    {   if(llDetectedKey(0)==llGetOwner())
        {   string what = llGetLinkName(llDetectedLinkNumber(0));
            if("start"==what)
            {   gTimeStart=llGetUnixTime()+5;
                gTimePause=0;
                set_media();
                llSay(0,"Starting movie");
            }else if("play/pause"==what)
            {   
                if(gTimePause)
                {   llSay(0,"Resuming playback.");
                    gTimeStart += 9 + llGetUnixTime()-gTimePause;
                    // the '9' skips back before the pause 
                    gTimePause=0;
                    set_media();
                }else
                {   llSay(0,"Movie paused.");
                    gTimePause=llGetUnixTime();
                    llClearLinkMedia(LINK_THIS,gFace);
                }
            }else if("skip-"==what)
            {   llSay(0,"Skipping back.");
                gTimeStart+=60; 
                // Yes, increment start time to go back is a bit counterintuitive.
                set_media();
            }else if("skip+"==what)
            {   llSay(0,"Skipping forward.");
                gTimeStart-=60;
                set_media();
            }else
            {   llOwnerSay(what);
            }
        }
    }
}

ETA: This rather simple script only accounts for people entering late, pause/resume and seeking through the video. It doesn't take into account the possibility that someone's connection might not be fast enough to play the video continuously without pausing or stuttering. the video file needs to have low enough quality that everyone can watch it comfortably. (if you're watching through SL, you're probably not ~that concerned with video quality anyway.)

Also, the video needs to be a literal video file (any commonly supported format should work) and not a page that directs to a video file player, even if that page is confusingly named with a misleading extension. This means you can't watch videos from <insert common streaming service here>. (unless you rip it and re-upload it to a file sharing site. )

 

Edited by Quistess Alpha
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 462 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...