Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to automatically record a video response after the video stops playing using flash

Using Mediaelementjs, i have successfully implemented a videoplayer, and triggered an end event which immediately pops up a flash recorder of adobe. Listing the website in Website Privacy Settings panel gives the direct access to microphone and camera via browser.

enter image description here

Question:
Is there a way to trigger certain function after the access to microphone and camera is allowed by the user, like start recording the video?

Can we somehow get to record the video immediately after user allows access to microphone and camera using flash.

like image 742
Sunil Lama Avatar asked Feb 11 '16 11:02

Sunil Lama


1 Answers

My answer would be of low quality, because I lost interest for Flash many years ago. The most polite way to put it: my skills of Flash are rusty. (by rusty, I mean Flash-8 ActionScript 2.0 / Flash CS4 ActionScript 2.0 level of rusty). What poses a real problem - I have no testing environment for Flash on my current computer. Thus, this would be a blind advice. Beware of bugs.

But, on the bright side, I did have experience of integrating Flash and Javascript. From what I see some of that is still relevant.

Short list of techniques that I know:

Javascript to Flash:

  1. ExternalInterface object provided by Flash allows Javascript execute methods inside of Flash - this could start animation or return data. Drawback: ExternalInterface could be prohibited by security settings or buggy implementation of plugin.

  2. document.getElementById('exampleMovie').SetVariable("someVariableName", "some text"); - to use this as message system - add Flash timer which would be listening - did a varialbe change

Flash to Javascript:

  1. ExternalInterface object provided by Flash allows Flash execute functions from Javascript. Drawback: ExternalInterface could be prohibited by security settings or buggy implementation of plugin.

  2. getUrl( 'javascript:someJavascriptFunction( "a", "b", true );' ); I am not sure if it was banned for security reasons but it could work. main drawback is that it's a one-way interaction.

I think that using External Interface is most logical way of implementing interaction.

Yes, you could use one-way interactions 2. and 2. to build communication protocol - I can even imagine that system... but that would be a bit too perverse ^ ^. + I can't find any data about browser support for 'SetVariable'. + Stackoverflow has a report of weird behavior of SetVariable in firefox SetVariable is not working in Firefox


Here is oficial documentation for External Interface: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html

That page has a browser compatibility table. Perhaps documentation needs update - no traces of Google Chrome which feels weird in my opinion...

Conceptually, you use External Interface like that:

// HTML
// id must be equal to name here
// and shouldn't contain symbols . - + * / \
<object id="exampleFlash" name="exampleFlash" ... >
    ...
</object>

// Javascript:
document.getElementById('exampleFlash').methodExposedForJavascript('value')

// ActionScript in Flash:
import flash.external.ExternalInterface;
ExternalInterface.addCallback( "methodExposedForJavascript", someInternalFunction );
function someInternalFunction( msg ) {
    // do something with msg - for example output it to existing txt field:
    _root.txtExampleTxt.text = msg;
}

The most relevant example is the last on that manual page http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html

Short instruction how to compile complex examples like that: http://help.adobe.com/en_US/as3/dev/WS9b644acd4ebe5999-2734bf3c124372a52ff-8000.html

They actually quite simple. Most percieved complexity comes from the fact that they generate elements of Flash programmatically - like

// all that this code does - is creating simple TextField in your movie
import flash.text.TextField;
package  {
    public class ABC extends Sprite 
    {
        private var output:TextField;
        public function ABC() 
        {
            output = new TextField();
            output.y = 25;
            output.width = 450;
            addChild(output);
        }
    }
}

This is done to make examples easier to express - but this is basically the same as 'use your GUI to create text field named output in your first frame'.

I'll try to cut away anything unrequired from that example. Pay attention to "receivedFromJavaScript" - this is a function that will be triggered by Javascript - you can add reaction inside.

Flash part:

package  {

    import flash.display.Sprite;
    import flash.events.*;
    import flash.external.ExternalInterface;
    import flash.text.TextField;
    import flash.utils.Timer;
    import flash.text.TextFieldType;
    import flash.text.TextFieldAutoSize;
    import flash.system.Security;

    public class ExternalInterfaceExample extends Sprite 
    {
        private var output:TextField;

        public function ExternalInterfaceExample() 
        {
            // constructor code
            Security.allowDomain("*");


            output = new TextField();
            output.y = 25;
            output.width = 450;
            output.height = 325;
            output.multiline = true;
            output.wordWrap = true;
            output.border = true;
            output.text = "Initializing...\n";
            addChild(output);


            if (ExternalInterface.available) {
                try {
                    output.appendText("Adding callback...\n");
                    ExternalInterface.addCallback("sendToActionScript", receivedFromJavaScript);
                    if (checkJavaScriptReady()) {
                        output.appendText("JavaScript is ready.\n");
                    } else {
                        output.appendText("JavaScript is not ready, creating timer.\n");
                        var readyTimer:Timer = new Timer(100, 0);
                        readyTimer.addEventListener(TimerEvent.TIMER, timerHandler);
                        readyTimer.start();
                    }
                } catch (error:SecurityError) {
                    output.appendText("A SecurityError occurred: " + error.message + "\n");
                } catch (error:Error) {
                    output.appendText("An Error occurred: " + error.message + "\n");
                }
            } else {
                output.appendText("External interface is not available for this container.");
            }
        }
        private function receivedFromJavaScript(value:String):void {
            output.appendText("JavaScript says: " + value + "\n");
        }
        private function checkJavaScriptReady():Boolean {
            var isReady:Boolean = ExternalInterface.call("isReady");
            return isReady;
        }
        private function timerHandler(event:TimerEvent):void {
            output.appendText("Checking JavaScript status...\n");
            var isReady:Boolean = checkJavaScriptReady();
            if (isReady) {
                output.appendText("JavaScript is ready.\n");
                output.appendText("ExternalInterface.objectID = " + ExternalInterface.objectID + "\n");
                Timer(event.target).stop();
            }
        }
    }
}

HTML:

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ExternalInterfaceExample</title>
<script>
    var jsReady = false;
    function isReady() {
        return jsReady;
    }
    function pageInit() {
        jsReady = true;
        document.forms["form1"].output.value += "\n" + "JavaScript is ready.\n";
    }
    function sendToActionScript(value) {
        document.getElementById("ExternalInterfaceExample").sendToActionScript(value);
    }
</script>
</head>
<body onload="pageInit();">

<object id="ExternalInterfaceExample"  name="ExternalInterfaceExample" 
type="application/x-shockwave-flash" data="ExternalInterfaceExample.swf" width="550" height="400">
<param name="movie" value="ExternalInterfaceExample.swf"/>
<param name="quality" value="high"/>
<param name="allowscriptaccess" value="always"/>
<a href="http://www.adobe.com/go/getflash">
    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"/>
</a>
</object>

    <form name="form1" onsubmit="return false;">
        <input type="text" name="input" value="" />
        <input type="button" value="Send" onclick="sendToActionScript(this.form.input.value);" /><br />
        <textarea cols="60" rows="20" name="output" readonly="true">Initializing...</textarea>
    </form>

</body>
</html>
like image 111
Jaiden Snow Avatar answered Sep 28 '22 16:09

Jaiden Snow