AIR 2.6 for iOS and video playback

If you work with audio and video streaming, one of the worst limitation of AIR 2.6 for iOS is that it is not possible to stream video encoded in H.264 (and audio in AAC) inside your AIR application. AIR 2.6 for iOS supports NetConnection and NetStream but can decode only Spark, VP6, MP3, NellyMoser and Speex formats. So no H.264 and no AAC (don’t ask me why).

This is a real problem. Who is using today VP6 for video streaming or MP3 for audio ? On top of that, the performance of audio/video streaming is not perfect in AIR for mobile today (even for Android) especially because you have a lot of dropped frames and no frame interpolation, so delivery a stream in VP6 and MP3 for iOS devices is a very sub optimal solution that cannot compete with the very good native streaming capabilities of iOS to which the user is accustomed.

The AIR for iOS documentation mentions that it is possible to launch the native iOS video player pointing to an .mp4 (or .m3u8) video file, but this is not handy because the video is opened outside the AIR application and especially for iPad the user experience is really bad.

Fortunately there’s a sufficiently working solution to integrate in the AIR app the flowless experience of the native player: use the StageWebView object.

The StageWebView object  is a powerful way to integrate the elements that AIR is lacking today. Do you need a list with perfect scrolling ? AAC audio streaming ? H.264 streaming ? Well you can use a StageWebView to load “HTML5” code inside the AIR app and integrate this kind of content. Let’s do a simple example:

var webView = new StageWebView();
webView.stage = this.stage;
webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight);
var path:String = new File(new File("app:/html/service.htm").nativePath).url;

This code will open a fullscreen instance of the native browser (without UI) and load a locally stored .html file (notice that it is necessary in iOS to use some hack like that at line 4 to obtain a valid url to access local html). Now you can easily understand that the best is to mix AIR UI and this windowed browser to exploit HTML5 capabilities especially for media streaming. A simple <video> tag inside the html code can do the job and offer perfect H.264 progressive and streaming playback to your AIR apps both in window and at fullscreen.

Communicate with StageWebView

It is not so easy to communicate with the page loaded inside the StageWebView. The object does not provide specifics API. Fortunately exist a class (StageWebViewBridge) developed to overcome the limitations of the standard StageWebView object. With StageWebViewBridge it is possible to communicate bidirectionally with the hosted html page and so create something similar to PhoneGap with Flash AIR.

Waiting for the future AIR 2.7 (which could have yet problems in the video area if it does not implement StageVideo in iOS) this is the best solution I found to overcome the limitations of AIR for iOS.


43 thoughts on “AIR 2.6 for iOS and video playback

  1. Thanks a lot for this post about these StageWebView/StageWebViewBridge classes. This is just what I was looking for! I’m trying to create a smooth scrolling list with text and images, and the iPad can’t cope with it (not even the iPad 2 with AIR 2.6 which is faster). Maybe this solution could work. Does this work in the regular Flash player 10.2 as well?

    But, where do you place your HTML files so they can be found from the AIR iOS app?
    I dont understand why this line is constructed like this:
    new File(new File(“app:/html/service.htm”).nativePath).url;

    Thanks again!

    1. StageWebView is an AIR feature only.
      You need to put the html in the root (or a subfolder) of your AIR app so that it is embedded as any other asset

  2. I see. Thanks for your response. So, is there a way to replicate StageWebView functionality in a Flash Player? I need to do both an iOS version and a Flash Player (browser) version of my app. Is there a way to embed a HTML browser in Flash?
    If not, I suppose the only thing I could do is put some CSS layer in the HTML that contains the SWF so it’s on top of Flash and try to communicate between it and Flash

  3. Well, I still havent tried video with StageWebView (I’m using it just for scrolling lists with lots of images for now, with the help of StageWebViewBridge by Spanish developer Pedro Casaubon). But if Sonnati says that it works, I assume he must have tried it before taking the time to write this blog post 😉

    I guess the video in the site you’ve posted isn’t working for you because it’s encoded with the OGG Theora codec. And the Safari for Mobile browser (the component used by StageWebView on iOS) only supports H.264 videos. You can learn about HTML 5 video support across browsers here:

    Try encoding your videos in MP4 H264 format. It should work.

      1. Anybody got a sample? I tried but I cant get it to work. The only thing I wanna do is play FMS livestream in an iOS app

  4. Thank you so much for this post – I’ve been struggling with video playback for a while. I’ve been able to get StageWebView to load just fine, but every HTML5 video I’ve tried to view shows a message that says “Your browser doesn’t support the video tag.” Is there something I can do to change this?

  5. Please take notice, that when using the stageWebView for media playback in AIR prior 3.0 on IOS with start of playback all sounds of the app are stopped.
    The sounds can not resume and no new sound can be played. Until the app is opened again or minizmized an then maximized again.
    Additional this sound bug will not occur in the debugger build, only in the other builds.
    It seems like, the app is not getting the IOS system sound focus again and so all souns are muted with out any error.

      1. Hi! I’m trying to load a mp4 (h264) video on a iPad with the AIR 3 Beta2, but it doesn’t work.. Did you try and make it work as you say?

        I made another test with a flv video, and I get the sound but no image,.. I don’t know what I did wrong as there is no “addChild” with stageVideo.. Any idea?

        Thanks for your help!

  6. @Konstantin: Does this sound bug occur in both 2.6 and 2.7?
    I’m halfway through a project that needs to play 1024×768 videos, I’m using stagewebview but have not tested switching sounds from webview to air.

    @sonnati: Have you tested the video capabilities of Air 3.0? I’m going to be releasing around Sept 20, can we already release apps with this beta build?

    1. StageVideo works well for AIR 3.0 but I have to do more tests. You can use the beta for final apps but at your own risk.

  7. I don’t think it’s a good idea to use a beta for a final commercial app.

    Also, Adobe states:

    “The pre-release program is intended for you to test your app and to share your feedback with us. Under the NDA participants have agreed to, you cannot use the pre-release builds for commercial purposes, and apps cannot be distributed with this software (including apps using captive runtime support). (private prerelease only)”

    Besides, any application compiled with the AIR 3.0 beta SDK will display a text in the upper right corner that says: “Adobe AIR 3 ( (Beta Build)”, which isn’t very professional to have in a commercial app 😉

  8. Yeah Oma, I read that too, that’s why I was asking sonnati about his comment.
    “Fortunately AIR 3 offers H.264 support in StageVideo” is not really a solution, we should be demanding an update to current AIr 2.7 in the same way they updated the GPU landscape bug.

    I have replicated the bug with 2.6 too. The weird thing is that if you play a stagewebview video before playing any sound objects, the following sound objects play just fine. It seem this only happen if you have already played the sound and then play the video. I wonder if this is a mixer problem with flash, since the video seems to fade and mute the air app. Have any of you guys trying messing with mixer volume properties?

  9. Dear Colleagues,

    We’re using Flash Builder 4.5.1 to develop an application that’s running on the iPad, streaming a video from Wowza Media Server using the NetConnection/NetStream object.

    We’re currently able to see the video in VP6 format (encoding live from a machine running Flash Media Live Encoder) and it runs fine on the iPad itself. However, it doesn’t work when we try using H.264, which is our need. Actually, we are able to see the h.264 video either on the PC or on Android, but not on the iPad. VP6, on the other hand, works on all devices.

    Here is what we’ve tried:

    1. We heard that the Air SDK 2.6 (which we were using) is not able to read video streams in H.264, so we downloaded the Air SDK beta and re-compiled the application, but still no luck.

    2. We also tried changing the “Additional Compiler Arguments”, by setting:

    3. We’ve tried using both Stage Video and Regular Video. Both of them are able to “connect” to the video and it logs a “playing” message, but no actual video is shown on the iPad (Android and PC are Ok).

    Are we missing something here? Any suggestions are greatly appreciated.

    Thanks in advance.

    Helder Conde

  10. Where (in what place) must I include your code:

    var webView = new StageWebView();
    webView.stage = this.stage;
    webView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight);
    var path:String = new File(new File(“app:/html/service.htm”).nativePath).url;

    …into .mxml file?

    Is a tag needed?

  11. Thanks for the great article Fabio.
    Air 3 says that it supports H.264 for iPhones etc – for http streams BUT not rtmp streams. And only if when stageVideo is used, not the video object.
    So the native player is still needed to play .flv’s using H.264/AAC.
    Is there any way to detect if an incoming stream is VP6 or H.264, so the correct player can be used?

    1. I solved my problem. In my situation I had one small video that I wanted to be bundled on the app and not require an internet connection. I abandoned the StageWebView hack and ended up converting my Quicktime movie into an FLV which I then imported into a movieclip embedded in an fla on the timeline of that movieclip (old school way). I gave that MC a class name and exported the fla as a .swc to include in my project. In my project I just instantiated that class and on my iPhone 3GS it worked fine. The performance is not ideal but it is acceptable. I found that FlashBuilder 4.6 with AIR 3 is coming out soon which will include StageVideo. When that’s out, I’ll update my code to use an H.264 .mov again and StageVideo for better performance.

  12. Can you post an example of the html that contains the html 5 video?
    I have tried the following simple example:

    Your browser does not support the video tag.

    But I get get the “Your browser does not support the video tag” when I run the app in the simulator.


    1. What kind of video are you trying to play and with what techinque ?
      Unfortunately StageVideo in iOS works only with http streaming

      1. Fabio,

        A quick question, just to make sure I understand it right: StageVideo via HTTP Streaming (on AIR 3.0) is the only method that allows streaming H.264 videos in iOS. Am I wrong? RTMP is possible only using VP6 or Sorenson. Did I miss something?

      2. I have tried a number of techniques.
        Local H264 Video (playing fine from iOS video player) via stage video using a slightly modified version of the SimpleStageVideo class by Thibault Imbert. It will always tell me that stage video is not available and try to play within a video object resulting in a grey box. If I switch off testing and just initialize stage video I get to see no video and no sound, the progress bar is running though and can be interacted with.

        Local H264 Video via stagewebview: If I point it to the video directly I only get a grey box. If I use a html document, the video tag will just be ignored and only text is displayed.

        Local FLV with Video object also results in a grey box.

        Am I missing something? It can’t be that difficult :-/

        I’m using flash cs 5.5 with the latest AIR 3 SDK. I wish there was just a code snippet available that worked for ios so I can understand what I did wrong.

        Do I understand you right that one can only play external videos with stage video in IOS?
        What is Adobe thinking?

      3. Are you sure it only works with RTMP? That didn’t make sense to me and reading this,, it looks like the video can’t be embedded in a swf and must use the NetStream object. I haven’t tested it yet but to me, that would mean for a mobile project, I could just include the H.264 external video file in my app bundle, then load the local file at runtime using the NetStream api, which if memory serves is not limited to RTMP (or remote files).

      4. Yeah, this should work for locally stored video H.264 files without requiring a remote server and RTMP. Still haven’t tested it but this example is from the NetStream docs:

        var my_nc:NetConnection = new NetConnection();
        var my_ns:NetStream = new NetStream(my_nc);;
        var my_video:Video = new Video();
  13. Working with AIR3 and h.264 videos in stagevideo on an iPad 1. Looks awesome, runs smoothly. I read that stagevideo can’t be accessed from the .draw method because it’s not a part of the display list. Does anyone know if there is an alternative method for taking a screenshot of the video like stagewebview does?

    I’ve tried decoding h.264 with regular video instead of stagevideo to be able to draw but nothing shows up.

    1. Could you provide short sample code. I’ve been trying but can’t get anything to show up on the iPad. The availability-event ist always negative, if I try anyways, it crashes. Maybe I have missed something in the Flash CS5.5 settings (although I think I overlayed the SDK correctly). Most people are getting this to run in Flash Builder. What are you using?

      1. this is what I’m doing, but I still haven’t found a way to copy the data to a normal bitmapdata

        nc = new NetConnection ( ) ;
        nc.connect ( null ) ;
        ns = new NetStream ( _nc ) ;
        ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, function(e){}, false, 0, true);
        ns.addEventListener(NetStatusEvent.NET_STATUS, VideoHandler, false, 0, true);
        ns.client = this ;
        video = new Video (1024,768) ;
        stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, StageVideoHandler);

        function StageVideoHandler ( event : StageVideoAvailabilityEvent ) : void {
        stage.removeEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, StageVideoHandler);

        if ( event.availability!=’unavailable’ ){
        if ( stageVideo == null ){
        stageVideo = stage.stageVideos [ 0 ] ;
        stageVideo.viewPort = new Rectangle ( 0 , 0 , 1024 , 768) ;
        stageVideo.attachNetStream ( ns ) ;;

  14. @sonnati: I have seen numerous posts on the web, where people have been unable to get H264 video streaming from FMS to work in AIR for IOS, which leads me to almost conclude that this is a *limitation* of AIR.
    If you have been able to get this to work, could you pls. post a sample FXP project, maybe using the sample video files that come with FMS? That would really help

    1. it is not possible to stream h.264 from FMS to AIR for iOS.
      it works only with VP6 and Spark.
      Recently has been introduced the support for H.264 playback with StageVideo but only for progressive downloaded video

  15. Dear colleagues,

    As Fabio Sonnati mentioned, AIR for iOS does support HTTP streaming (via HLS) of h.264 videos. However, when streaming via RTMP, AIR for iOS only supports VP6 and Spark – a couple of old, retired codecs.

    While HTTP streaming (HLS) seems to be a good option for those who simply want to “play a video” in iOS, I do believe it has some severe limitations, especially for live-communications. I’d like to share some of these thoughts with you.

    1. HLS has ridiculously high latency for live videos (around 40 seconds), when compared to RTMP. Although this may not be a problem for on-demand videos, it sure is a great problem for anyone doing serious live-communications applications (such as webconferencing, live webcasting with audience interaction or Skype-like video chats), which require near-zero latency.

    2. HTTP streaming will not allow cuepoints to be read from videos. This is particularly painful for anyone doing video-triggered actions, such as slide changes (for webinar apps), subtitling or live closed captioning, etc.

    3. Although HLS it is quite compatible with firewalls (since it flows through port 80), RTMP with tunnelling also flows through port 80 or 443, which adds great compatibility, even on very restricted networks. Our experience with very large clients proves that, hands down.

    In other words, HTTP streaming is Ok. But it simply does *not* fit into every shoe that RTMP does. We do believe that RTMP remains as our best option for live streaming or serious streaming-oriented *apps* (in which things more complex than “mere video playing in a window” actually happen).

    That all said, I do believe we should let Adobe know about this need. The fact that RTMP streaming in AIR for iOS is limited to VP6 and Spark, which are two “dead” codecs, still puts us, Air developers, in a very fragile position in terms of what we can accomplish with video in iOS.

    I’m sure some of you cheered when you heard about Flash Player 11 having h.264 video encoding. This, (plus the echo cancellation feature that came in 10.3) opened great doors for great Unified-Communication applications to be developed for Flash/Air. Now, it’s undeniable that clients want those applications running on tablets, especially the iPad.

    Not being able to use h.264 via RTMP on iOS is certainly a huge step backwards. Anyone shares this same opinion? What do you guys believe to be the best option to let Adobe really know about this need? Is this limitation a simple lack-of-a-feature (which can be fixed by Adobe) or is this some imposed thing by Apple?

    Just one final note: Air for Android does *not* have the same limitation. It does allow RTMP streaming of h.264.

    Thanks for your attention,

    Helder Conde

    1. Hi Helder
      I agree Android allow RTMP streaming of h.264 but I am facing a very long delay (about 25-30 seconds) on my android when I playback my h.264 encoded live video. When same video is received on web application it plays wells without delay but don’t know what is happening for Android and getting this long delay.

    2. Hi Helder
      I agree Android allow RTMP streaming of h.264 but I am facing a very long delay (about 25-30 seconds) on my android when I playback my h.264 encoded live video. When same video is received on web application it plays wells without delay but don’t know what is happening for Android and getting this long delay.

  16. Where I can found a demo video VP6 or some kind of which can be playable inside an iOS (?) I’m using AIR 3.1 with FB 4.6 now!

    1. I would also be interested in that example! 🙂
      My next try is going to be encoding a live feed with vp6, publishing it to FMS 4.5 and try to consume with my iPhone 4s in air for iOS with RTMP. Hopefully I’ll get a positiv result, Im trying to figure out why I cant see Video on my device even with the correct output from the NetStream… (btw, simulator works fine, problem is after I deploy on device). Im starting to think that the live video feed is being encoded in h264… maybe thats the reason that it doesn’t work…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s