Change font size
It is currently Sat Feb 16, 2019 8:22 am

Forum rules


{L_IMAGE}



Post a new topicPost a reply Page 1 of 1   [ 2 posts ]
Author Message
 Post subject: Generic Video Player
PostPosted: Sun Aug 18, 2013 11:40 am 
Furious Typer

Joined: Mon Apr 22, 2013 11:41 am
Posts: 87
Location: Texas
This is a generic, menu driven video player using media-on-prim. I created it to stream mp4's from a web server, but it should be adaptable to other formats.

It essentially works like this: the root prim contains the script and a notecard for each "category" of video. Touching the player will give you a menu of categories. To add a category, add a new notecard; the script will automatically detect the new card and add it to the menu.

Choosing a category will call up a menu taken from the notecard. Each video gets two lines on the notecard, one for the video title to be displayed in the menu, and one for the URL that will be played when the button for that video is pushed. Notecard structure looks like this:
{L_CODE}:
Video1
http://www.mysite.com/myvideos/video1.mp4
Video2
http://www.mysite.com/myvideos/video2.mp4

In addition, every menu has an "Off" button. Pressing this will clear the media from the prim and display the default texture, which can be pretty much anything. You should make sure that Full Bright is checked, or the videos will be kinda dim.

Buttons in the menus are not sorted in anyway (I haven't gotten around to that yet), so they pretty much display in the order they are listed in the notecards.

Word of warning: when the video is playing touching the face with the video won't work. I got around this by creating a frame around the root prim. Touching the frame will always call up the menus.

Please note that there is a delay between pressing a menu button and the start of the video, or the video turning off. This is delay is built into the media-on-prim function, so there is no way to get rid of it that I know of.

I'm not going to claim that this is very well written or efficient, but it does work, and I find that the ability to add categories and/or videos using notecards is really convenient, since you don't have to edit the script at all.

k, the script:
{L_CODE}:
integer channel_dialog;
list buttons = ["Off"];
key ToucherID;
string message;
integer listenID;
string category;

get_categories()
{
    integer n = 0;
    while (llGetInventoryName(INVENTORY_NOTECARD,n) != "")
    {
        buttons = buttons + llGetInventoryName(INVENTORY_NOTECARD,n);
        ++n;
    }
}

get_videoList(string category)
{
    integer NumLines = osGetNumberOfNotecardLines(category);
    integer n;
    for(n=0;n<NumLines;n=n+2)
    {
        string NoteCardLine = osGetNotecardLine(category,n);
        if (NoteCardLine != "")
        {
            buttons = buttons + NoteCardLine;
        }
    }
}

play_video(string vid_url)
{
    llSetPrimMediaParams(2,
        [
            PRIM_MEDIA_ALT_IMAGE_ENABLE, 1,
            PRIM_MEDIA_CURRENT_URL, vid_url,
            PRIM_MEDIA_AUTO_LOOP, 1,
            PRIM_MEDIA_AUTO_PLAY, 1,
            PRIM_MEDIA_AUTO_SCALE, 1,
            PRIM_MEDIA_PERMS_CONTROL, PRIM_MEDIA_PERM_NONE
        ]);
}

string get_video(string title)
{
    integer NumLines = osGetNumberOfNotecardLines(category);
    integer n;
    for(n=0;n<NumLines;++n)
    {
        string NoteCardLine = osGetNotecardLine(category,n);
        if (NoteCardLine == title)
        {
            NoteCardLine = osGetNotecardLine(category,n+1);
            return NoteCardLine;
        }
    }
    return "";
}

default
{
    state_entry()
        {
        llClearPrimMedia(2);
        channel_dialog = -1 - (integer)("0x" + llGetSubString( (string)llGetKey(), -7, -1) );
        state main_menu;
        }
}

state main_menu
{
    state_entry()
    {
        buttons = ["Off"];
        message = "\nChoose a category.";
        get_categories();
    }
         
        touch_start(integer num_detected)
        {
            ToucherID = llDetectedKey(0);
            llDialog(ToucherID, message, buttons, channel_dialog);
            listenID = llListen(channel_dialog, "", ToucherID, "");
        }

        listen(integer channel, string name, key id, string message)
        {
            if (message == "Off")
            {
                state default;
            }
            else
            {
                category = message;
                state sub_menu;
            }
        }
}

state sub_menu
{
    state_entry()
    {
        buttons = ["Off"];
        message = "\nChoose a video.";
        get_videoList(category);
        llDialog(ToucherID, message, buttons, channel_dialog);
        listenID = llListen(channel_dialog, "", ToucherID, "");
    }

    listen(integer channel, string name, key id, string message)
    {
        if (message == "Off")
        {
            state default;
        }
        else
        {
            play_video(get_video(message));
        }
        state main_menu;
    }
}


Top
 Profile  
 
 Post subject: Re: Generic Video Player
PostPosted: Sun Aug 18, 2013 6:06 pm 
Furious Typer

Joined: Mon Apr 22, 2013 11:41 am
Posts: 87
Location: Texas
Oh, I forgot to mention. The reason there is no llListenRemove is that the listeners automatically get removed during a state change, which occurs after a menu choice.... though now that I think of it I should probably use a timer to do that in case a button isn't pressed.... grrr lol


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


Who is online

Users browsing this forum: No registered users and 2 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:  
cron


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