Jump to content

Watch Videos Together (Sync Parcel Media)


Evah Baxton
 Share

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

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

Recommended Posts

Since I am hearing about the new synced streaming media features coming down I figured I would give this some completion for posterity.

Place this script on a prim in your land.
Set the media texture on one of the faces of the prim.
Touch the prim and press play.
You'll need to start media in your viewer if you don't have "auto play" enabled. If there is ever a problem, usually you need to stop and restart your media in the viewer.

New features:
Dialog menu to control the video.
Only lets the owner use video controls.
Now syncs in subseconds.

Check it out in action: Miramare (206, 21, 27)

//Evah Baxton 2020
integer videoLength=4873; //Video length in seconds
integer resync=5; //ReSync every 5 seconds
string mediaURL = "https://ia800502.us.archive.org/33/items/House_On_Haunted_Hill.avi/The_House_on_Haunted_Hill_512kb.mp4";
integer loop=1; //Loop the synced video
integer displayTime=1; //Display time and status. 

integer resyncStart=0;
integer scrubStart=0;
integer playing=0;
float start;
float diff;
key owner;
integer channel;
integer scrub;
integer paused=0;
string curMode;
float pauseTime;
string curStatus;
integer listenR;
integer listenRTimeOut;

list order_buttons(list buttons) {
    return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4)
        + llList2List(buttons, -9, -7);
}

string convertTimeToString() {
    integer now = (integer)(llGetTime()-start);
    integer seconds = now % 60;
    integer minutes = (now / 60) % 60;
    integer hours = now / 3600;
    return llGetSubString("0" + (string)hours, -2, -1) + ":" 
        + llGetSubString("0" + (string)minutes, -2, -1) + ":" 
        + llGetSubString("0" + (string)seconds, -2, -1);
}

default {  
    state_entry() {
        owner = llGetOwner();
        llParcelMediaCommandList([
            PARCEL_MEDIA_COMMAND_STOP,
            PARCEL_MEDIA_COMMAND_URL,mediaURL
        ]);
        llSetTimerEvent(0.5); 
    }
    
    touch_start(integer num_detected) {    
        key avatar = llDetectedKey(0);
        if(owner==avatar) { 
            channel = (integer)(llFrand(-1000000000.0) - 1000000000.0);
            listenR = llListen(channel,"", "","");
            llDialog(owner,"\nPlease choose:\n",
            order_buttons(["<< RW", "FF >>", "STOP []", "PAUSE ||", "PLAY >","REPEAT","TOGGLE INFO"]),channel);
            listenRTimeOut=llGetUnixTime()+10;
        } else {
            llInstantMessage( avatar, "You aren't the owner." );
        }
    }
    timer() {
        if(llGetTime()-start < 0) {
            start=llGetTime();
        }
        if(paused==1) {
            start = llGetTime()-pauseTime;
        } 
        
        diff = llGetTime() - start;
        
        if(paused==1) {
            llParcelMediaCommandList([
                PARCEL_MEDIA_COMMAND_TIME, diff,
                PARCEL_MEDIA_COMMAND_PAUSE
            ]);    
        }
        
        if(displayTime==1) {
            if(playing==1) { 
                curStatus="Play >";
            }
            if(paused==1) {
                curStatus="Paused ||";
            }
            if(scrub>0) {
                curStatus="<< REW";
            }
            if(scrub<0) {
                curStatus="FWD >>";
            }
            if(loop==1) {
                curStatus=curStatus+" [REPEAT]";
            }
        
            if(playing==1 || paused==1) {
                llSetText(curStatus + " " + convertTimeToString(), <1.0,0,0>,1.0);
            } else {
                llSetText("Stopped.", <1.0,0,0>,1.0);
            }
        } else {
            llSetText("",<1.0,0,0>,1.0);
        }
        
        if(llGetUnixTime() > listenRTimeOut) {
            listenRTimeOut=0;
            llListenRemove(listenR);
        }
        
        if(llGetUnixTime()%resync) {
            if(llGetTime()-start>0 && llGetTime()-start<start+videoLength) {
                start=start+scrub;
            }
            if(resyncStart==0) {
                resyncStart=1;
                if(playing==1) {
                    llParcelMediaCommandList([
                        PARCEL_MEDIA_COMMAND_TIME, diff
                    ]);
                }
        
                if(llGetTime()-start >= videoLength) {
                    if(loop==0) {
                        llSetTimerEvent(0.0);
                    } else {
                        llResetTime();
                        start = llGetTime();
                        llParcelMediaCommandList([
                            PARCEL_MEDIA_COMMAND_STOP,
                            PARCEL_MEDIA_COMMAND_PLAY
                        ]);
                    }
                }
            }
        
        } else {
            resyncStart=0;
        }
    }
    
    listen(integer _chan, string _name, key _id, string _option) {
        curMode=_option;
        llListenRemove(listenR);
        if(owner==_id) {
            if(_chan==channel) {
                if(_option=="<< RW") {
                    scrub=10;
                    paused=0;
                }
                if(_option=="FF >>") {
                    scrub=-10;
                    paused=0;
                }
                if(_option=="STOP []") {
                    scrub=0;
                    playing=0;
                    start=0;
                    paused=0;
                    llParcelMediaCommandList([
                        PARCEL_MEDIA_COMMAND_STOP
                    ]);                    
                }
                if(_option=="PAUSE ||") {
                    scrub=0;
                    playing=0;
                    paused=1;
                    pauseTime=llGetTime();
                    llParcelMediaCommandList([
                        PARCEL_MEDIA_COMMAND_PAUSE
                    ]);
                }
                if(_option=="PLAY >") {
                    scrub=0;
                    playing=1;
                    paused=0;
                    if(start==0) {
                        llResetTime();
                        start = llGetTime();
                        llSetTimerEvent(0.5); 
                    }
                    llParcelMediaCommandList([
                        PARCEL_MEDIA_COMMAND_URL,mediaURL,
                        PARCEL_MEDIA_COMMAND_PLAY
                    ]);
                }
                if(_option=="LOAD NEW") {

                }
                if(_option=="TOGGLE INFO") {
                    if(displayTime==0) {
                        displayTime=1;
                    } else {
                        displayTime=0;
                    }
                }
                if(_option=="REPEAT") {
                    if(loop==1) {
                        loop=0;
                    } else {
                        loop=1;
                    }
                }
            }
        } else {
            llInstantMessage( _id, "You aren't the owner." );
        }
    }
}

 

Edited by Evah Baxton
  • Thanks 4
Link to comment
Share on other sites

Hello, 

Im very curious about the current state of "Media on a Prim" (MOAP) 

after returning to use SL after a long time

I have in my inventory a media player from way back

its call A2Z LABS HUD camera

it was great and now it seems it doesnt work

Now i try a new item called 'GIANT CINEMA SCREEN'

which does play Youtube video, but is limited in its capabilities for instance it cannot play a webcam or other kind of video source, it can play a URL

Anyone else interested in this topic perhaps can share info

thankX in advance

Polystar Park

Snapshot_002.png

Snapshot_003.png

Snapshot_001.png

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1529 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...