15 October 2007
Intermediate
Video is arguably the most compelling media found today on the web. The new trend is to create web applications that use video as a means in the social network jungle to easily broadcast yourself. Video on mobile devices represents a new challenge for both device manufactures and developers. Flash Lite 3 opens an amazing new world to mobile developers.
Mobile Web 2.0 exists in the definition of Web 2.0 but it dramatically changes the way people use the content. For the most part, we are consumers of content created, produced, and edited from traditional media providers for classic "screens" like cinema, TV, PC, etc. With the Mobile Web 2.0, the user becomes also a producer of content because they can supply content and can interact with the content with rating, comments, etc.
The role of the video in this scenario is very important because now we can really create mobile applications that work like "classic" web applications that use video.
Flash Lite 3 adds new capabilities and brings itself as one of the most compelling platforms because it is able to create something more than a classic mobile TV. With Flash Lite 3 you have several options for playing back video:
Flash Lite 3 adds support for Flash video (FLV) that is rendered directly in the Flash Lite player rather than by the device, so you no longer need to be concerned about whether your target devices support a particular video format. The Camera class and recording video are not supported by Flash video with Flash Lite 3. The video codecs supported by Flash Lite 3 are:
In this article I will focus on the local playback of an FLV file directly from a Flash Lite 3 application.
When creating this sample application, I didn't used any external classes because my aim with the application is to show how easy it is to start using the FLV format in a mobile application. Use the following steps to create application. For your reference completed version application is included in the sample files for this article, which are linked above.
Note: At the time of writing of this article, only generic Flash Lite 3 profiles are available. Once devices from original equipment manufacturers (OEMs) start to ship, those device profiles will be available in a future device profile updates.
test_video in the Property inspector.video_txt used by the application in order to show the name of the video and the position of the playhead, in seconds.fscommand2("SetSoftKeys", "", "Exit");
NetConnection class and an instance of the NetStream class that are now supported by Flash Lite.var ncVideo:NetConnection ;
var ns:NetStream;
This sample application is able to reproduce FLV files inside the video instance and show the name of the video and the position of the playhead in seconds. In order to complete these things you need to declare an Array with the paths and names of the video and a variable used in order to store a reference to a setInterval call used to check the playhead position. Enter the following code.
Note: You will need to change walk.flv and lake.flv as well as the names in the following code to the names of your FLV files and the appropriate descriptor text.
var check:Number;
var videos:Array = [{path: "video/walk.flv", name: "Walk Video"}, {path: "video/lake.flv", name: "Lake Video"}];
var tmpObj:Object = {};
tmpObj.onKeyDown = function():Void{
..................
}
Key.addListener(tmpObj);
onKeyDown function, you need to handle the press of the right soft key or the press of key 1 or 2 in order to launch the video. The body of the function contains these instructions:if (Key.getCode() == ExtendedKey.SOFT2) {
fscommand2("Quit");
return;
}
var index:Number = chr(Key.getCode());
if(!isNaN(index) && (index >= 1 && i <= 2)){
index = index - 1;
playVideo(videos[index].path, videos[index].name);
}
The playVideo function accepts two arguments. The first one is the path of the video and the second one is the name of the video.
NetConnection and NetStream instances are initialized, and then start the reproduction of the video file attaching it to the video instance you have placed on the stage.if(!ncVideo){
ncVideo = new NetConnection();
ncVideo.connect(null);
}
if(!ns){
ns = new NetStream(ncVideo);
}
ns.play(file);
test_video.attachVideo(ns);
if(!check)clearInterval(check);
check = setInterval(getTimeInfo, 300, ns, name, video_txt);
TextField instance you placed on the stage with the name of the video and the playhead position in seconds.function getTimeInfo(ns:NetStream, nm:String, txt:TextField):Void{
txt.text = "Playing video: " + nm + " " + Math.round(ns.time);
}
Now you are ready to test the application with Adobe Device Central.
If you are new to mobile development, you have to carefully consider the testing phase of your development process and test the application as much as possible on your target device. Adobe provides you with Device Central in order to simulate the functionality of your application on a rich set of devices.
When you test your application in Device Central, you'll be surprised about the capabilities offered from this software (display panel, memory panel, performance panel, etc.) and from its behavior with Flash video files. You are able to get a very accurate preview of you mobile video application simply by exporting your FLA file (Control + Enter) and using the keyboard of the selected device (see Figure 4).
If you want to improve the user experience of this sample application you may apply some interesting features of Flash Lite and video.
As I have already said, the Flash Lite 3 player now supports FLV files and you can treat your video instance as classic video. For this reason you can apply support for transparent overlays (alpha channels) and rotation on the video instance.
test_video and use this movie clip to create a motion tween with an alpha effect (see Figure 5).
videoHolder_mc and modify the ActionScript contained in the playVideo function in order to set the ns variable of the clip and start the playback of its timeline.videoHolder_mc.ns = ns;
videoHolder_mc.play();
In this article you have learned the basic concepts behind the new video capabilities of Flash Lite 3, and what you need to load a local video and apply an alpha channel. Now it is time to start to work on your video applications and take all the advantage of the new video capabilities of Flash Lite 3 that open a new world to all developers. With this release of Flash Lite 3, you don't need to worry about the video supported in your target devices—and you can benefit from all the terrific features of Flash video.