Video Formats and Video Volume in Flash Lite 3.x

Introduction

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. I am writing this article to elaborate the issue behind this and a workaround that can be done in Flash Lite 3.0.

I shall also explain the different types of formats that are involved (Native and Device).

Video Format Types

There are two major types of formats involved in media for Flash Lite. Device and Native video formats.

Device Video

Device videos are the formats that are decoded by the device and Adobe Flash Lite player uses the device APIs to decode and playback/render the video on the screen. A device video cannot be streamed. The reason is that the run time (FL) does not understand the format and hence it can just load a local video as a complete chunk and play (without returning the progress, duration and some other metadata information). Flash Lite just talks to the platform and passes the area that the platform should play the video on and the platform renders the video. This is also the reason why overlay of any other element is not possible in this case. Video always remains in front. The below information lists some of the device video formats 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+

Native Video

Native videos are the ones which are decided by Flash Lite itself and rendered on screen. Below information lists the native video formats supported by Flash Lite 3.x (varies for platforms and FL versions) : -

  • On2 (TrueMotion VP6)
  • Sorenson Spark (Sorenson Video Quantizer)

Real Time Messaging Protocol Video Variants

Flash Lite 3.0 supports only the RTMP (Real Time Messaging Protocol) format among all the following variants: -

  • RTMP – Supported
  • RTMPT – Not Supported
  • RTMPS – Not Supported
  • RTMPE – Not Supported
  • RTMPTE – Not Supported
  • RTMFP – Not Supported

Volume Control, Why not in Flash Lite 2.x?

The reason why it is not possible to control volume in Flash Lite 2.0 is, Flash Lite 2.0 supports only embedded videos and to be more specific, embedded device videos. Since Flash Lite 2.0 supports only embedded device videos, Flash Lite 2.0 uses the device APIs and renders it on screen, thus NOT exposing any APIs to Action Script to control the same. This is the reason I am suggesting a workaround here for Flash Lite 3.0 content developers to achieve this.

Controlling Volume of Flash Lite 3.0 Native Video

Let’s get into the implementation part for Flash Lite 3.0. The criteria I am taking up here is about Native videos only and streaming videos only (local/network). Hence, for streaming videos, I shall be using NetStream and NetConnection classes. The general implementation of video playback script doesn’t fall into this tutorial, as I would concentrate more only on the workaround involved in controlling the volume of a Net Streamed video. So, below you can see the code part for loading and streaming a video from an http location. This, I assume, would exist in your content 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 above code, NetConnection and NetStream variables are declared. We place a video object on the stage by right clicking on the library and selecting “New Video…”, and then dragging the symbol to the stage. We give it an instance name – “video_vid”. Now is the step for controlling the volume of the video. Since NetStream cannot have volumes changed directly, we follow the below steps to achieve it: -

  1. Create a new empty MovieClip.
  2. Attach the Audio from netstream to the newly created MovieClip.
  3. Create a new Sound object for the newly created MovieClip that has the audio attached from NetStream.
  4. Control the volume control of the Sound object.

So here is the code to do the same: -

this.createEmptyMovieClip("videoSound_mc", 2)
videoSound_mc.attachAudio(ns);
video_snd = new Sound(videoSound_mc);
video_snd.setVolume(75);

That’s it! Now you should see the volume of the video playback to play in 75% volume.

Further Enhancements

Further, the last statement that calls “setVolume” can be used in functions to implement slider volume control components, buttoned volume control components, text, etc. I hope you liked this tutorial/article. Thanks for reading.

VN:F [1.9.13_1145]
Rating: 1.0/5 (1 vote cast)
Video Formats and Video Volume in Flash Lite 3.x, 1.0 out of 5 based on 1 rating

  • http://mobile.podblogr.com/ Bruce Hopkins

    This is great news. Does Flash Lite 3 support streaming audio?

  • Hemanth Sharma

    FL 3.1 supports MP3 streaming. Not 3.0.

    - Hemanth

  • Sunil

    I heard FL 4.0 is coming, how different is it from FL 3.1? I only know it supports AS 3.0 replacing AS2.0 from FL 3.0.
    Regards,
    Sunil

  • http://www.hsharma.com Hemanth Sharma

    FL 4.0 doesn’t replace AS2… It has both the virtual machines to run AS2 as well as AS3.

    Try visiting my new post for more information – http://www.hsharma.com/tech/flash/india-game-dev-summit-2010-slides/

    Though not much described, I have showcased Accelerometer in one of the slides and pictures of the event too.

  • Supriya Tenany

    Hi Hemanth,

    The link http://flash-reference.icod.de/NetStream.html mentions the way an flv is streamed as also in your post. But I do not understand how to play (as you have mentioned streaming is not possible for device video) device videos in the format of a .3gp

    Regards,
    Supriya Tenany

  • http://www.hsharma.com Hemanth Sharma

    Supriya, I received your detailed mail on the same. I thought it would be better replying here so others having similar doubts would get things cleared.

    > FLV is the only native video format for Flash Lite.
    > 3GP is a device video format and not native.
    > The above code should work just fine for a device video too (though I haven’t tried it explicitly). It just won’t stream it. But it should play it once fully loaded. Embedding a device video also works fine. You might want to try both. Drop me a mail in case you have any other issues.

  • Ramesh

    Is there any way to control volume for device video while streaming from an RTSP server?

    Thanks
    Ramesh

  • http://www.hsharma.com Hemanth Sharma

    I believe not :(

  • SunnySingh

    Hi, if most FL versions do not support streaming video/music etc.. why use FL? What are workaround/combinations? What new Device Deck platform is better suited to network driven services, like streaming music, etc..?

  • http://www.hsharma.com Hemanth Sharma

    You will see Flash Player 10.1 coming to many more smart phones in the near future. That is full Flash Player on mobile. You might have to target that platform. FL 3.x supports video streaming. FL 4.0 supports ActionScript 3.