Wednesday, September 21, 2011

Adobe Flash and Windows 8

While Microsoft has said that Adoble Flash has no place in the Metro UI in Windows 8, Adobe has different ideas.
In a blog post by Danny Winokur over on the Flash Platform Blog, it’s clear that Adobe sees Flash as playing a pivotal role in Windows for years to come.
We expect Windows desktop to be extremely popular for years to come (including Windows 8 desktop) and that it will support Flash just fine, including rich web based games and premium videos that require Flash. In addition, we expect Flash based apps will come to Metro via Adobe AIR, much the way they are on Android, iOS and BlackBerry Tablet OS today, including the recent number one paid app for the iPad on the Apple App Store, Machinarium, which is built using Flash tools and deployed on the Web using Flash Player and through app stores as a standalone app.
While nothing will change with respect to plug-in support for the classic Windows 8 desktop, Microsoft has decided to give plug-ins the shove with respect to the Internet Explorer 10 ‘Metro UI’ browser. Instead, Microsoft is cutting legacy ties when it comes to Metro and pushing HTML5 over proprietary plug-ins such s Flash.
The reasons given by Microsoft for dropping plug-in support in Metro is performance, efficiency and security - three points that make a lot of sense when it comes to tablets. But the Metro UI isn’t confined to tablets. Microsoft is pushing the Metro as the default ‘desktop’ for all, and this means that ‘default’ support for technologies such as Flash are no longer present in Windows, and some people aren’t happy.

Sunday, September 11, 2011

FLASH REMOTING WITH AS3

Using remoting in AS3 is actually quite simple. Remoting calls are now made directly through NetConnection, so there's no need for Remoting classes or components, everything you need is readily available. Here is a quick example.

This is a wrapper class for NetConnection that makes sure we are using the right AMF encoding. The default is AMF3, which is not supported on AMFPHP versions lower than 2.0. So, we use AMF0 instead. Save this class as "RemotingService.as".

/*************************** FLASH CODE **************************************/
package
{
    import flash.net.NetConnection;
    import flash.net.ObjectEncoding;

    public class RemotingService extends NetConnection
    {       
        function RemotingService(url:String)
        {
            // Set AMF version for AMFPHP
            objectEncoding = ObjectEncoding.AMF0;
            // Connect to gateway
            connect(url);
        }
    }
}
/*****************************************************************/

The next class is just a test that uses the previous class to make a call. Save it as "RemotingTest.as".

/**************************** FLASH CODE *************************************/
package
{
    import flash.net.Responder;

    public class RemotingTest
    {
        private var rs:RemotingService;

        function RemotingTest()
        {
            init();
        }

        private function init()
        {
            rs = new RemotingService("http://your.domain.com/amfphp/gateway.php");
            var responder:Responder = new Responder(onResult, onFault);
            var params:Object = new Object();
            params.arg1 = "something";
            params.arg2 = "2";
            rs.call("Class.method", responder, params);
        }

        private function onResult(result:Object):void
        {
            trace(result);
        }

        private function onFault(fault:Object):void
        {
            trace(fault);
        }
    }
}
/*****************************************************************/

Given the following PHP class, the previous exercise could be easily adjusted to print "something and 2" to the Output panel. Just copy it to the 'services' folder of your AMFPHP installation, and replace "Class.method" with "Test.test" on the RemotingTest class.

Save this PHP FILE AS Test.php

/************************ PHP CODE *****************************************/

class Test
{

    function __construct()
    {
        $this->methodTable = array(

                "test" => array(
                "description" => "Tests service",
                "access" => "remote"
            )
        );
    }


    function test($params)
    {
        return $params['arg1'] . " and " . $params['arg2'];
    }

}
?>
/*****************************************************************/

Friday, September 9, 2011

How to connect with Flash media server - For beginner

What is FLASH MEDIA SERVER ?


Flash media server is one of the best server created to connect multiple clients in to a single virtual world. Flash media server used for many reasons, few of them as follows

1. For Video live telecast
2. For Video live recording & Telecasting
3. For Online Video Broadcasting with DRM in a secured way
3. For Online Chatting application
4. For Online Video Conferencing
5. For Online Multi-user Application or Multi-Player game development
and many more

How to install and Where to install Flash Media server ?


For testing purpose you can install the server in your local machine, But if you whish you access using Internet from other machines, then you need to install it in a dedicated webserver machine. Now a days many hosting sites like www.influxis.com providing you shared media server access with less cost. Please note, Better to install the media server in the higher bandwidh system, So that it can serve better even the load is heavy.

Setup the connection folder


Before creating our flash coding, we need to setup the application folder to connect with. For that Copy server-side script files for an application to the folder you registered on the server. For example, for an application called "videoPlayer", copy the main.asc file to RootInstall/applications/videoPlayer. You can also place server-side scripts in "scripts" subfolder. For example, you can use either of these locations:

RootInstall/applications/appName

RootInstall/applications/appName/scripts

Note: To replace a running application, copy the new files, then use the Administration Console to restart the application.

Sample Main.asc code :



application.onConnect = function (client1){


application.acceptConnection(client1);


client1.call("welcome");


};


Copy media files to the server

Copy video and audio files to the streams/_definst_ folder in the application folder:

RootInstall/applications/appName/streams/_definst_/

If an application connects to an instance of the application, for example, nc.connect("rtmp://fms.example.com/appName/someInstance"), place the streams in the following folder:

RootInstall/applications/appName/streams/someInstance/

There are several ways to configure the server to look for media files stored in other locations. See the Adobe links for more information


How to connect using RTMP


RTMP is the protocol used by Adobe’s Flash Media Server to stream content into flash. Most of the help documentation doesn’t touch much on this method of connection and is limited to sources not easily available to users.


This article should be used by those with an understanding of video playback using actionscript 2. If that isn’t you, please read this article before continuing.

1.) In order to use the RTMP protocol, you will need to install and run a version of Adobe Flash Media Server. Adobe has released a free developer version the limits you to 10 connections. That will be MORE than enough to do some basic development. Please make sure you are running or have access to a Flash Media Server before continuing to the next step.

2.) Now that you have access to a Flash Media Server, we will start with some basic code that should look familiar if you have worked with actionscript and video before. For this step, you will need to know the URI for the server. If you installed Flash Media server on the machine you are running on, you can use "localhost" for the URI. We will be using the "vod" app that comes pre-installed on the server for this example.

var nc:NetConnection = new NetConnection();
nc.connect("rtmp://YOUR_SERVER_URI/vod/");

Note : If we were loading an flv file without streaming, you would have passed null to the connect() method instead.

3.) The only thing left is to load the stream, instead of loading an FLV video from a URL. This is actually much easier than you think. Instead of passing a URLRequest to the NetStream.play() method, you would instead pass the name of the stream you wish to play from within your app (this is the name of the FLV file on the server, but without the .FLV extension). To playback an HD streaming file, you will need to format your stream name slightly different: "mp4:NAME_OF_STREAM.mp4", "mp4:NAME_OF_STREAM.m4v"

Please note that you can not setup your NetStream until after the NetConnection has successfully connected. You will know this from the NetStatus event: NetConnection.Connect.Success that is dispatched.

var ns:NetStream = new NetStream(nc);
ns.play("NAME_OF_STREAM");

// ns.play("NAME_OF_FLV"); // No Suffix or prefix required for FLV file format
// ns.play("mp4:NAME_OF_STREAM.mp4"); // this will stream an HD movie instead.
// ns.play("mp4:NAME_OF_STREAM.m4v"); // this will stream an HD movie instead.
// ns.play("mp3:Audio_File_Name"); // No .mp3 suffix, to play MP3 files


SAMPLE RTMP VIDEO PLAY BACK USING FLASH AS2


var my_nc:NetConnection = new NetConnection()
my_nc.connect("rtmp://localhost/vod");

var my_ns:NetStream = new
NetStream(my_nc);

my_nc.onStatus = function(info:Object){
trace("[
NET CONNECTION STATUS ] :: " + info.code);
if(info.code ==
"NetConnection.Connect.Success"){
my_ns.setBufferTime(3);
//Here
my_video is the Video component created from Library
my_video.attachVideo(my_ns);
my_ns.play("SampleFLV");
//my_ns.play("mp4:SampleHDVideo");
//my_ns.play("mp3:SampleMP3File");
//my_ns.play("mp4:SampleM4VFile.m4v");
}
}

This code is applicable for WOWZA Media server too. Connection method is same for FMS and WOWZA Media Server






Monday, September 5, 2011

Flash Combo Box corrupted when loading

There are lot of issues with Flash AS2 components, It is all because of the uncleared global styles. Components styles are stored in a global variable, Which is not getting cleared even after removing the entire component from the SWF file.

Because of this Some time the dynamic components are displayed as corrupted. For example we can take ComboBox component. Test the following scenario in you flash file.



  1. Create a New Flash file, Drag and drop two ComboBox V2 component in to your stage and add some values to display

  2. Make one Combo enabled and other one as disabled.

  3. Save it as myCombo.fla, Now publish the file and close it.

  4. Create a New Flash file and name it ComboTest.fla and place a Button on stage, and place an empty movieclip say "content_mc" on stage.

  5. To the button Provide the functionality to unload the Existing content from content_mc and load the "myCombo.swf". The unloading is usefull to remove the existing content before loading a new one.

  6. Now Publish your ComboTest.fla file

When you run the file, it will display the Combobox element perfectly without any error. But if you unload the content and reload the SWF, Oops the disabled Combobox displayed as corrupted. The Dropdown part of the disabled combo displays as wiered boxes.

This problem is due to uncleared global Skin variables. You can test this in your Flash file by doing this simple step.


Load a Component into a MovieClip, Then remove it completely from your swf file. Now Click on "Debug" Menu button in your SWF window and select "List Variable" menu item.

It will display you a number of uncleared Variables. Few important variables are listed below
_global.mx;
_global.style;
_global.cascadingStyles;
_global.styles;
_global.skinRegistry;
_global.getStyleCounter;


To reset your skin problems you need to clear the "skinRegistry" variable to do this just delete the variable

delete _global.skinRegistry;

So, If you are facing problem with component skinning, Just delete the skinRegistery and load your component.

Thats it, it will work



Sunday, September 4, 2011

Capture image from Flash movie or video using AS3

It was very tricky and hard to capture image from Flash in AS2. We need to write a bunch of lines to read the pixels and convert it as a readable bytearray using our code need to send it to a server side script like ASP or PHP to save it as IMAGE (JPG/PNG)

Now the Adobe Image encoder class provide you the ability to capture any part of your movieClip or a Video and then convert it to Image

Following sample code will show you how to use the ImageEncoder class

Encoding the MovieClip

In this example, we are going to assume that our MovieClip of interest is named target_mc. In order to make use of the JPEGEncoder, our MovieClip needs to become a bitmap.
To do this, we are going to use the BitmapData class. The contructor for this class requires two arguments: width and height. Since we want our jpeg to be the same size as target_mc, we use it’s width and height properties. Then by using target_mc as an argument, the draw method draws our MovieClip on to the bitmap.


/************************************************/
import com.adobe.images.JPGEncoder;
var jpgSource:BitmapData = new BitmapData (target_mc.width, target_mc.height);
jpgSource.draw(target_mc);
/************************************************/



Now that target_mc is in bitmap form, we can use the JPGEncoder. When creating a new instance of this class, you can set the level of compression by passing in a number from 1 - 100.

Then to create our jpeg, we call the encode method and use our BitmapData instance as the argument. The encode method returns the jpeg in the form of a ByteArray, which is simply an AS3 class that makes working with binary data a little easier.

From the Flash Player to the Hard Drive

ActionScript 3 has done all the work neccessary to turn our MovieClip into a jpeg, but it needs a little help in making it available to download. To make this happen, we will need to post our ByteArray to a server side script using the URLRequest class. Since we are posting binary data, we must set the content-type to "application/octet-stream". It is also important to note that the file being downloaded will need a name, so we pass that to our server side script as a query string.

Final CODE in FLASH

/************************************************/
import com.adobe.images.JPGEncoder;

var jpgSource:BitmapData = new BitmapData (target_mc.width, target_mc.height);
jpgSource.draw(target_mc);

var jpgEncoder:JPGEncoder = new JPGEncoder(85);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);

var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("jpg_encoder_download.php?name=sketch.jpg");
jpgURLRequest.requestHeaders.push(header);

jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;

navigateToURL(jpgURLRequest, "_blank");
/************************************************/


Below is the php script to where we are posting our jpeg. I chose to use php for this example, but any server side script will do.

PHP - Server side SCRIPT

/************************************************/
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{

// get bytearray
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];

// add headers for download dialog-box
header('Content-Type: image/jpeg');
header("Content-Disposition: attachment; filename=".$_GET['name']);
echo $jpg;
}
/************************************************/


That's it, Creating image from flash is that much easy.


Download Sample Code

Download AS3 Adobe Core Lib (Including JPGEncoder)


- Reference : Henry jones -

Math.random

There’s a lot of times, in programming, when you need a number that’s random, or (loosely speaking) unpredictable. For instance, if you have a game in which the throwing of dice is simulated. For that sort of need, ActionScript has a built-in constant, written exactly like so:
Math.random()
The Adobe LiveDocs give the following description of our friend Math.random():
“a pseudo-random number n, where 0 <= n < 1″
That certainly makes it clear, doesn’t it? If you’ve had maths in school, or rather, if you could remember it at all, you’d know that the Math.random() number falls within this interval:
[0, 1>
The square bracket means that 0 is in the interval, and the open bracket means that 1 is not. And that means that these are the sort of numbers Math.random() generates:
0
0.374539
0.2
0.999999999
0.45311
Et cetera. So the lowest number you could get is 0, and the highest is very close to, but never quite, 1.
How is that useful to you?
Say you need to simulate the flipping of a coin. Then you need either a 0 or a 1. How could you ever achieve that with Math.random()?
Luckily, there are 3 methods for rounding in ActionScript that you can call to the rescue. They are:
Math.ceil()
Math.floor()
Math.round()
Math.ceil() rounds numbers to the nearest higher integer.
Math.floor() rounds numbers to the nearest lower integer.
Math.round() rounds numbers to the nearest integer, whether it happens to be a higher or a lower one.
If you want to get familiar with this, do the Math.random exercise, and you'll soon feel comfortable with this stuff.
So if I want a number that's either 0 or 1, what do I use? You guessed it:
Math.round(Math.random());
Mind all the brackets! Can't afford to miss even one, or you'll get an error thrown at you.
And what do I do if I want a whole number between 0 and 10?
Well, Math.random() = a number between + including 0 and 0.99999999999 [it goes on infinitely, of course]. So if I just multiply the whole Math.random() thing by 10, I get: a number between 0 and 9.999999999. If I round this, I get a whole number between 0 and 10. So we use:
Math.round(Math.random()*10);
What if I want a whole number between 6 and 117?
Well, Math.random() = a number between + including 0 and 0.9999999999, so if I multiply Math.random() by 117 and round it, I get a whole number between 0 and 117. So that won’t work. The trick is to multiply Math.random() by (117 – 6) = 111, and then add 6! And, of course, round the whole thing again. So you get:
Math.round(Math.random()*111) + 6;
This way, ActionScript takes Math.random(), or a number between 0 and 0.9999, multiplies it by 111 to get a number between 0 and 110.9999999, then rounds those to get a number between 0 and 111, and finally adds 6 to the whole enchilada, resulting in: a number between 6 and 117.
Of course you’re not going to remember that. I would never expect you to! I’m just going to provide you with a little formula which you can look up, any time you need it, in the Very Handy Reference. Here it is:
to get a whole number between a and b, use:
Math.round(Math.random()*(b-a)) + a
-Thanks Actionsscriptmoron-

Monday, August 24, 2009

HOW TO CUT A VIDEO USING FFMPEG?

Hope most of you are working in Social networking websites and video blogging websites.

Cutting a particular portion of a video from the source video file is little tricky and will create long delay in the process.

More over all the tools available in the market are too expensive and not having all the features like some free tool.

I prefer to use one of the free tool since it is having all the capability like the paid tool.

One of the best tool i came across was FFMPEG. It is a gift for Online video editors.
Yes its amazing performance and options really make you mad.

Now we are going to see how to cut a flv video, Which means we are going to split a particular portion of a FLV video into a new file (Which we are going to use in our site)


The simple command for Cutting the video is
ffmpeg -sameq -ss [start_seconds] /
-t [duration_seconds] -i [input_file] [outputfile]



Now we will see what are those arguments.

-ss position (Seek to given time position in seconds. “hh:mm:ss[.xxx]” )

-t duration (Set the recording time in seconds. “hh:mm:ss[.xxx]”)

-i filename (input filename)

-sameq (Use same video quality as source (implies VBR))


Here is a sample usage
ffmpeg -sameq -ss 00:00:20 -t 00:00:40 -i flv_video.flv out_flv.flv


Enjoy :)