Sunday, July 10, 2011

Using the ZipCodeValidator class to validate US or Canadian zip codes

The following example shows how you can use the ZipCodeValidator to validate either US or Canadian zip codes (or should that be “postal codes” for our friends from the Great White North?). It turns out that making the ZipCodeValidator “Canadian friendly” is as simple as setting the domain property, and passing a constant value from the ZipCodeValidatorDomainType class (valid constants are US_ONLY and US_OR_CANADA).
Full code after the jump.
View MXML
<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/25/using-the-
zipcodevalidator-class-to-validate-us-or-canadian-zip-codes/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.validators.ZipCodeValidatorDomainType;
        ]]>
    </mx:Script>

    <mx:ZipCodeValidator id="zipCodeValidator"
            source="{zipCode}"
            domain="{ZipCodeValidatorDomainType.US_OR_CANADA}"
            property="text"
            trigger="{button}"
            triggerEvent="click" />

    <mx:Form>
        <mx:FormHeading label="Enter shipping zip code" />
        <mx:FormItem label="Zip code:">
            <mx:TextInput id="zipCode" maxChars="10" />
        </mx:FormItem>
        <mx:FormItem>
            <mx:Button id="button" label="Validate" />
        </mx:FormItem>
    </mx:Form>

</mx:Application>

How to decrease the loading time of initial downloaded .swf file ?

The major issue that i realize in adobe flex large application is the initial loading time.Sometime when .swf file size is large then Flex take a lot of time for loading at the client side and this effect the user experience.
But don’t worry Adobe give us some alternate to resolve this problem.I will give you only brief introduction is as follow
1) Modular applications
Modules are SWF files that can be loaded and unloaded by an application. They cannot be run independently of an application, but any number of applications can share the modules.
Modules let you split your application into several pieces, or modules. The main application, or shell, can dynamically load other modules that it requires, when it needs them. It does not have to load all modules when it starts, nor does it have to load any modules if the user does not interact with them. When the application no longer needs a module, it can unload the module to free up memory and resources.
Modular applications have the following benefits:
  • Smaller initial download size of the SWF file.
  • Shorter load time due to smaller SWF file size.
  • Better encapsulation of related aspects of an application. For example, a “reporting” feature can be separated into a module that you can then work on independently.
  • Modules are similar to Runtime Shared Libraries (RSLs) in that they separate code from an application into separately loaded SWF files. Modules are much more flexible than RSLs because modules can be loaded and unloaded at run time and compiled without the application.
click here to see example and more information about the Modules application
2) Runtime Shared Libraries
Another way to reduce the size of your applications’ SWF files is by externalizing shared assets into stand-alone files that can be separately downloaded and cached on the client. These shared assets can be loaded and used by any number of applications at run time, but are transferred only once to the client. These shared files are known as Runtime Shared Libraries or RSLs.
When multiple applications share a core set of components or classes, clients can download those assets only once as an RSL rather than once for each application. The RSLs are persisted on the client disk so that they do not need to be transferred across the network a second time. The resulting file size for the applications can be reduced. The benefits increase as the number of applications that use the RSL increases.
Applications built with Flex support the following types of RSLs:
  • Framework RSLs — Libraries of components and framework classes that all applications can share. Framework RSLs are precompiled for you. Adobe provides hosted, signed framework RSLs that you can link to from any application that has internet access. For more information, see Using the framework RSLs.
  • Standard RSLs — A library of custom classes created by you to use across applications that are in the same domain. Standard RSLs are stored in the browser’s cache. For more information, see About standard RSLs.
  • Cross-domain RSLs — A library of custom classes, like standard RSLs, with the difference being that they can be loaded by applications in different domains and sub-domains. Cross-domain RSLs are stored in the browser’s cache. For more information, see About cross-domain RSLs.
You can create your own RSLs from custom libraries. You do this by using either the Adobe® Flex® Builder’s™ Build Project option for your Flex Library Project or the compc command-line compiler.

Migration from FlexSDK without changing flash player version.

• if you are using a window then here in the following path

C:\Program Files\Adobe\Adobe Flash Builder 4\sdks4.5.0\frameworks\libsplayer

HERE create a folder name with flash player version like "10.0 " and place a "playerglobal.swc" file into this folder.
and in the flash builder goto following option
project-->properties-->flex compiler
here set the flash player version like 10.0.0

Remove unused file from the .swf file

Basically we have seen in flex sdk 4 and sdk 4.5, when we compile the flex code lot of unused file is also embedded into the .swf file . These unused file increases the .swf file size that mean when we will use this .swf file then this will take lot of time for load that we have normally seen.

For solve this problem follow the following steps.

1) In flash builder 4 or 4.5 click on the Item"project" in menu bar

2)select option "Export" release Build"

3)new window will be open here you can give the name of the export "release build folder" By default name of release folder is bin-release. click on finish.

You can use this release folder same as the bin-debug folder.here .swf file size is 45 to 50 % less then the bin-debug folder .swf file.

Comparison between FMS 4,Wowza media server and Red5

Comparison table

Feature

Flash Media Server(FMIS 4)

Wowza Media
Server 2

Red5

Protocols supportedRTMP
RTMPT
RTMPS
RTMPE
RTMPTE
RTMP
RTMPT
RTMPS
RTMPE
RTMPTE
RTMP
RTMPT
RTMPS
RTMPE
RTMPTE
Developer edition10 Connections (Free)10 Connections (Free)Free
Pricing$4500$995Free(Open Source)
Supported Platforms Microsoft® Windows Server® 2003 with Service Pack 2 or Windows Server 2008
Linux® Red Hat® 4 or 5.2
Runs as a 32-bit software on both 32- and 64-bit operating systems.
Windows
Mac OS X
Linux
Solaris
Unix
64-bit Support on all
Windows
Debian/Ubuntu
Mac OSX
WAR
Gentoo
Audio / Video Streaming (live and on-demand)FLV
H.264FLV
MP3
AAC, LC-AAC, HE-AAC
Speex
FLV
H.264FLV
MP3
AAC, LC-AAC, HE-AAC
Speex
(On Demmand)
FLV
MP3
F4V
MP4
AAC
M4A(Live)
Sorenson
VP6
h.264
Nelly Moser
MP3
Speex
AAC
NSV
Multi Client/ Multi Protocol StreamingFlash (RTMP)Flash (RTMP)
iPhone (HTTP Streaming)
Silverlight (Smooth Streaming)
QucikTime/3GPP (RTSP/RTP)
IPTV (MPEG-TS)
Flash (RTMP)
RecordingH.264/AAC to FLV container
MPEG-4
H.264/AAC to FLV container
H.264/AAC to MP4 (Quicktime) container
FLV Only
Action Method Format 3 (AMF3) AMF3AMF3AMF
Server Side AS2JavaJava

Speex vs Nellymoser

License type: Nellymoser is closed format codec whereas Speex is opensource which means that files created using speex can be decoded or encoded without any licence requirement.

What is speex :Speex is a new audio codec introduced in flash player 10 and above. It overcomes many limitations of old Nellymoser codec. This new codec will provide better audio quality using less bandwidth. Speex can be used for both kind of communication , through Flash Media Server or P2P.Speex is opensource so it can be decoded or converted to any format unlike nellymoser .


Speex Description:
Speex encoder and decoder are present in flash player 10 and above. Speex compression is controlled by setting encodeQuality. Encode quality can be set using 11 quality levels 0(Lowest) - 10(Highest).Default value is 6. Speex encoder for flash works in constant bit-rate (CBR) . Speex is designed for Voice over IP (VoIP) which means it provides high quality speech at low bit rate.

Flash Player Requirement: Nellymoser works from Flash player 6 onwards whereas Speex requires atleast Flash Player 10. Although speex works with flash player 10 but there is a audio disturbance bug on listener end which was fixed in version 10,0,22,87.So player 10,0,22,87 and above is recommended.

Quality: Speex is optimised for speech so better quality is expected from speex as compared to our old Nellymoser codec.

Bandwidth Requirement: Speex delivers better quality than Nellymoser using less bandwidth as compared to speex.our tests revealed that the quality with nellymoser becomes usable at 8(16kbps) where as in case of speex it is 3 (9.80 kbps).The highest quality in Speex uses 42.2 kbps thats half of the bandwidth being used by nellymoser which is 88.2

Encode Quality: Speex provides more flexibilityby giving 11 levels of quality to choose from (0-10).0 is lowest and 10 is highest audio quality. Nellymoser gives 5 settings(5,8,11,22,44) ,5 is lowest and 44 is highest quality.Remember more is the quality higher is the bandwidth requirement which may lead to choppy sound when sufficient bandwidth is not available.

Speex

Speex Quality , Bandwidth and filesize table
Quality (encodeQuality)Required bandwidth in kbpsPer minute file size in KB
03.9528.9
15.7542.1
27.7556.7
39.8071.7
412.893.7
516.8123.0
620.6150.8
723.8174.3
827.8203.6
934.2250.4
1042.2309.0


Nellymoser

Quality(mic.rate) Required bandwidth in kbps

5 11.025
8 16
11 22.05
22 44.1
44 88.2

Sunday, March 27, 2011

How to use the SPEEX codec in video streaming for better audio encoding

Speex has a better audio sound encoding then Nellymoser.

we can use this only in above flex 4 sdk and flash Player 10 or above.

var mic: Microphone= Microphone.getMicrophone();

mic.codec = SoundCodec.SPEEX;