Requirements  
Prerequisite knowledge
Required products
Basic understanding of the Flash authoring environment and prior
experience developing mobile applications using Flash Lite 3.0 is recommended.
Adobe Animate CC CS4
User Level  
All
 

 

As mobile devices become more sophisticated, developers continue to stretch the boundaries of the content they deliver to handsets. Video delivery is one avenue that has a promising future in mobile devices, but there is still much trailblazing to be done to successfully present it over the current mobile networks. Recently I came across a question in the forums that asked for a method to control the volume of an embedded video in Flash Lite 2.0. This is clearly not possible. However, the challenge intrigued me and I investigated possible strategies for controlling the sound of digital video in mobile applications. I am writing this article to elaborate my findings in this area and to share a workaround that can be accomplished in Flash Lite 3.0 with the online community.
 
In addition, I'll also explain the different types of video formats that are involved (native and device video) and provide information about the currently supported codecs available for mobile developers.
 

 
Working with supported video formats and codecs

The addition of digital video to your mobile application adds significant value by offering the user a fully immersive experience. However, it is important to have a clear understanding of the type of video formats that are supported in order to develop applications that provide a seamless delivery of the media without any display issues.
 
The constraints of the processor speeds of handsets and the limitations of the mobile device networks can be challenging, but with perseverance it is possible to deliver and control video playback on devices. In this section I'll describe the different types of video formats,
 
 
Video formats
There are two major types of video formats used in media for Flash Lite applications:
 
  • Device
  • Native
 
Device video
Device videos are categorized as the type of video format that are decoded by the device itself. In this situation, Flash Lite player leverages the device's APIs to decode and playback (render) the video on the handset screen. A device video cannot be streamed; it must first be downloaded before playing.
 
The reason device videos cannot be streamed has to do with the decoding process. The run time executable (Flash Lite application) does not understand the video format and therefore it can only load a local video as a complete chunk and play it back (without returning the progress, duration and other metadata information). Flash Lite player can communicate to the platform, and this communication allows the information regarding the area where the platform should play the video to be passed to the device. At this point, the device platform renders the video.
 
The decoding process for device video is also the reason why it is not possible to overlay any other element on top of the device video in the mobile application. Device video always remains in front when displayed on the screen.
 
The following list of device video and audio codecs are supported by Symbian Mobile Platform:
 
 
Video Codecs:
  • H.263
  • PO L10
  • MPEG-4
  • Real Video (7, 8, 9 and 10)
 
Audio Codecs:
  • AMR-NB
  • Real Audio 7,8,10
  • AAC
  • AAC+
Note: These are not all-inclusive lists.
 
 
Native Video
Native videos are categorized as the types of video formats that are decoded by Flash Lite player and are then rendered on the handset screen. Since Flash Lite player is responsible for the decoding, you have the opportunity to use ActionScript to control how the video plays.
 
The following list of native video formats are supported by Flash Lite 3.x:
 
  • On2 (TrueMotion VP6)
  • Sorenson Spark (Sorenson Video Quantizer)
Note: The list of supported native video formats will vary depending on the specific platforms and versions of Flash Lite player you use to develop your project.
 
 
Supported RTMP (Real Time Messaging Protocol) video formats
Of all the different flavors of RTMP video, Flash Lite 3.x only supports the standard RTMP (Real Time Messaging Protocol) video format; other variants are not supported:
 
  • RTMP - Supported
  • RTMPT - Not supported
  • RTMPS - Not supported
  • RTMPE - Not supported
  • RTMPTE - Not supported
  • RTMFP - Not supported
In the next section, I'll describe a strategy you can use to control the soundtrack of a native video that is streaming in a Flash Lite 3.x mobile application.
 

 
Controlling the volume of video during playback

When I first began researching the information covered in this article, the forum post that triggered my interest asked if it was possible to control the volume of the video displayed in a mobile application built with Flash Lite 2.x.
 
After investigating, I determined that unfortunately it is not possible. Flash Lite 2.0 only supports embedded videos—and to be more specific, it only supports embedded device videos.
 
Flash Lite 2.0 uses the device's APIs to render embedded video on the screen of the handset, which means the APIs of the device are not exposed to ActionScript to allow you to control the parameters of the playback.
 
I continued to look for a way that sound control of the video could be achieved, and eventually developed the workaround presented below that allows you to use Flash Lite 3.0 to achieve this goal.
 
 
Using Flash Lite 3.0 to control the volume of native video
In the following section, I'll describe how to implement volume control in a mobile application with Flash Lite 3.0. To be clear, for this strategy to work it is important to only use native videos that are streaming (either locally or over the network). Since this code will be controlling streaming videos, it takes advantage of both the NetStream and NetConnection classes.
 
A description of the general implementation of video playback scripts is outside the scope of this article. The information provided here focuses on the workaround involved in controlling the volume of a video by attaching the audio from the NetStream to a movie clip.
 
The code example below contains the script for loading and streaming a video from an HTTP location. This article assumes that this code exists in your project already:
 
// DECLARING NetConnection AND NetStream VARIABLES var video_nc:NetConnection = new NetConnection(); video_nc.connect(null); var video_ns:NetStream = new NetStream(nc); // HANDLING THE STATUS OF NetStream ns.onStatus = function(info) { if (info.code == "NetStream.Play.Start") { // PLAYBACK STARTED } if (info.code == "NetStream.Play.Stop") { // PLAYBACK STOPPED } if(info.code == "NetStream.Buffer.Full") { // BUFFER FULL } if(info.code == "NetStream.Buffer.Empty") { // BUFFER EMPTY } }; // HANDLING THE METADATA OF THE NetStream ns.onMetaData = function(info) { // METADATA OF THE VIDEO }; // ATTACHING THE NETSTREAM TO THE VIDEO OBJECT ON STAGE video_vid.attachVideo(ns); // PLAY THE STREAM ns.play("http://www.mysite.com/video.flv");
In the code shown above, NetConnection and NetStream variables are declared to enable the video streaming.
 
To set this up, you need to place a Video object on the Stage. Right-click (Windows) or Control-click (Mac) on the Library and select "New Video..." from the Library Panel menu. Drag the new video symbol to the Stage, and while it is still selected, use the Property inspector to assign the following instance name: video_vid.
 
This next part is the workaround that you can use to control the volume of the sound of video. Since NetStream does not support the ability to adjust the volume directly, you can follow the steps outlined below to achieve this goal:
 
  1. Create a new empty movie clip.
  2. Attach the audio from the NetStream to the movie clip created in Step 1.
  3. Create a new Sound object for the newly created movie clip that has the audio attached from NetStream.
  4. Use ActionScript to control the volume of the Sound object.
Use the following code to set the volume of the Sound object:
 
this.createEmptyMovieClip("videoSound_mc",2) videoSound_mc.attachAudio(ns); video_snd = new Sound(videoSound_mc); video_snd.setVolume(75);
Choose Control > Test Movie to check it out (and make sure your speakers are turned on). After adding these changes, the soundtrack of the video in your project should play back at 75% of the original volume.
 

 
Where to go from here

To extend this code and make further adjustments to control the audio, you can work with the the last statement in the example above that calls the setVolume method. You can use this in your functions to implement slider volume control components, volume control components (buttons), text, and any other sound-related features that you'd like. Now that the Sound object can be manipulated, you can take advantage of ActionScript to add the controls you need for your mobile application.
 
To learn more about how to extend this code, see the online help for Developing Adobe Flash Lite 3.x Applications to see ActionScript examples. Specifically, check out the section titled Working with Video.
 
And be sure to visit both the Flash Developer Center and the Mobile and Devices Developer center to get helpful articles and sample projects to take your projects to the next level.