September 25, 2008

AIR: Creating a custom status bar

It’s easy to create your own customised status bar for AIR applications. For my example, I wanted to be able to display a network status icon that indicates whether the application is connected – this is bound to a state set by AIR’s network service monitor, via Cairngorm.

First of all, in your application MXML file, make sure showStatusBar is set to true, add the statusBarFactory parameter and point it to your custom component:

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
    layout="absolute" 
    showStatusBar="true" 
    statusBarFactory="{new ClassFactory(CustomStatusBar)}">

Then just make a new MXML component called CustomStatusBar and add any elements you want to display in your new status bar. There are a couple of things AIR will be expecting from a StatusBar, most importantly the status setter and getter methods required to display status text:

<?xml version="1.0" encoding="utf-8"?>
<mx:HBox width="100%" 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    backgroundColor="#E3E1E1" 
    >
    <mx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import uk.ac.warwick.filesclient.model.AppModel;
            [Bindable] private var modelLocator:AppModel = AppModel.getInstance();

            [Bindable] public function get status():String
            {
                return this.statusText.text;
            }

            public function set status(value:String):void
            {
                this.statusText.text = value;
            }

            private function showNetworkStatusIcon():void
            {
                var path:String = "";
                if(modelLocator.isNetworked)
                {
                    statusIcon.source = "greenlight.png";
                } else {
                    statusIcon.source = "greylight.png";
                }
            }
        ]]>
    </mx:Script>
    <mx:Label id="statusText" paddingLeft="7" fontAntiAliasType="advanced"/>
    <mx:Image id="statusIcon" 
    toolTip="Network status"  
    horizontalAlign="right" 
    width="100%" 
    height="10" 
    verticalAlign="middle" 
    render="showNetworkStatusIcon()"/>
</mx:HBox>
You can add almost anything you like in there with this technique; animations, custom text etc. Here’s a quick screen grab of my basic custom status bar with its status light on green after a bit more tweaking of the layout and styling – nothing amazing, but its useful to be able to add your own elements when required (click to enlarge);

Status bar

September 18, 2008

Flex unit testing and continuous integration with FlexUnit, Ant and Selenium

Here’s a couple of really useful guides to setting up a continuous Flex testing and integration framework using FlexUnit, Ant and Selenium, written by my friend and ex-colleague Kieran at Black Pepper, and his colleague Julia. The articles cover setting up FlexUnit and Ant and then creating acceptance tests using FlashSelenium:


September 10, 2008

Flex IoC frameworks: which?

I need some Flex framework advice; I’m about to start a couple of new AIR projects, and decided that instead of using Cairngorm again it would be a good idea to try a different framework. There’s no particular reason to move away from Cairngorm – I’ve become reasonably comfortable with how it works and what it does, and I like it, but I’d also like to explore other approaches to Flex development. Last time I looked around there were a few alternatives, but in the few months since I posted that entry a number of new frameworks have appeared, and the amount of choice has increased considerably.

At first I thought I’d go for PureMVC – it seems like a popular framework in general, but around here our Java development is based on Spring, and I’d quite like to explore the dependency injection/IoC concepts at the core of Spring in a Flex app, to learn for myself how to apply such patterns in a context I’m familar with.

As far as I can tell, there are three IoC frameworks – Prana is a lightweight IoC container for PureMVC, Mate, which looks really well-thought out, with good documentation, and finally Swiz, which also looks interesting. I’m just not sure which will help me get into IoC as quickly as possible, coming from Cairngorm. I suspect I’ll go for PureMVC with Prana, but if anyone has any advice/insight it would be useful!


September 09, 2008

Silverlight to support H.264, AAC

Follow-up to <video> and Flash from [Ux]

Microsoft has announced that Silverlight will be supporting AAC audio and H.264 video. With regard to my previous entry about the video tag, this will make it even harder for Theora and can only consolidate H.264 as the current codec of choice. The announcement comes as no surprise to industry experts, but this move proves that MS is aggressively going after online video in a big way, but I’m not sure anyone really wins – based on browser/OS install base Silverlight may become more of a threat than the video tag would have been.

I’ve also been thinking a little more about Chrome – given that YouTube is part of Google it’s likely that when Chrome supports the video tag, the embedded codec(s) Google chooses could have a huge impact. Considering that H.264 is already being used on YouTube, perhaps that would be the default choice?


September 08, 2008

<video> and Flash

The availability of a Firefox 3.1 alpha (and Safari 3.1) with video tag support has prompted a few people to proclaim that Flash will soon be replaced as the primary medium for playing video on the web. I think predictions of Flash’s demise are both premature and inaccurate, and also think there’s a possibility that the introduction of the new tag could cause more problems than it was intended to solve. Why? – codecs…

Firefox (and Opera) will support one embedded codec in the first instance, Theora. Theora is completely open-source but based on an older-generation codec, On2 VP3. Flash currently uses VP6 and H.264, Quicktime Player supports H.264 and Silverlight adds support for VC-1, one of the newest kids on the video block. All are newer, higher-quality formats than Theora (typical comparison here). That’s not to say Theora is a bad codec, far from it, but in the world of video codecs it is at least a generation old, maybe more, and as such doesn’t represent the current best of breed in terms of video quality/performance.

Secondly, in order to take over from Flash, Theora needs to be on all or enough browsers to work as a standard. The HTML5 specification doesn’t advocate or recommend any codecs, and as the specification notes, this is problematic:

It would be helpful for interoperability if all browsers could support the same codecs. However, there are no known codecs that satisfy all the current players: we need a codec that is known to not require per-unit or per-distributor licensing, that is compatible with the open source development model, that is of sufficient quality as to be usable, and that is not an additional submarine patent risk for large companies. This is an ongoing issue and this section will be updated once more information is available.

So, if one browser advocates Theora, will every other browser follow? After all it’s a fairly trivial (and zero-licencing cost) thing to include support for it. Firefox and Opera combined currently have around 25-30% share of the browser market; while 30% (and growing) is an excellent starting point to build from, IE’s and Flash’s dominance in terms of installed base will make it difficult forTheora to overtake the current popular formats unless they support it too.

We’re not starting with a blank sheet of paper here either; many video services and sites that use video have spent a considerable amount of time and investment in encoding to a specific platform, one that is currently supported by enough browsers/platforms to make it worthwhile. At best a move to Theora would have to be transitional, and likely to take several years, as people migrate content over to the new format. IE is the most common browser by a considerable margin, and Microsoft has its own favoured formats; WMV via Windows Media Player and/or VC-1 via Silverlight, plus the formats supported by Flash Player. It’s hard to see these not being with us for a while yet, unless IE starts supporting Theora at the expense of Windows Media formats (unlikely); if Theora isn’t included in IE, it simply isn’t going to get traction as quickly as it needs to to become the standard. Similarly unless Webkit (as the core engine of Chrome and Safari) or YouTube also add native support for it (AFAIU latest Safari builds that support the video tag currently support Quicktime’s supported formats, which doesn’t include Theora as standard), it’s hard to see it taking over. While users will be able to add new codecs manually, assuming they will do so in order to view a new video format could be risky. Then there’s streaming support via RTSP/RTMP, etc.

My point is we are going to have to live with multiple formats whether we like it or not, and that Theora is a technically a backward step; it will only take one browser vendor to ignore Theora and it will become void as a standard, yet HTML5 isn’t forcing or even recommending a standard to follow. At this point video on the web will be in danger of becoming a mess as people find they don’t have the required codec and have to install support for it. I wouldn’t go as far as to suggest the video tag is going to create chaos where relative calm currently exists, but it might. I can’t see a good technical reason why the current model of using Flash as a wrapper for video and codec support is broken, or why it needs to be replaced with what may become a mess of format support where we move from two or three dominant formats to five, six or maybe more competing ones, plus multiple downloads for users. In my experience proprietary formats tend to be better, that’s why they cost, and neither do I buy into the ‘everything has to be open-source’ argument, especially considering that the dominant audio format is MP3, which isn’t an open-source format at all (even AAC codecs require patent licence).

Most importantly though, while all this takes place a solution already exists; Flash Player. It supports H.264, VP6 and Sorenson, most people already have it and it works on all the browsers mentioned above, across Windows, Linux and Mac. “But Flash is a terrible resource hog!” I hear you say, but when you consider that Flash is decoding and rendering video, in software, it’s worth noting that this takes CPU cycles and is a processor/memory intensive task. Even if you could run fully-hardware accelerated video (which Flash is moving towards), video is still relatively intensive work for the average desktop/laptop. In the first instance, Theora decoding in Firefox is going to run in software, just like Flash, and presumably consume CPU cycles in a similar way.

With all this in mind it would seem to me that the only reason for wanting to take Flash off its video pedestal is that it is owned by a commercial entity, ignoring the fact that Flash Player has been a key enabler and driver of the dramatic increase in use of video on the web, without any of the ‘payback’ people seem to fear. Without advocacy from W3C, the reality is that browsers are going to be free to implement their own choice of favoured codecs, but those choices are likely to be driven by different criteria, not necessarily whether they are open-source. It could be about to get messy.

Alternatively, we could all start using Mike Chambers’ workaround for getting Flash to display video wherever the video tag is used, and everyone could just carry on. ;-)


Search:

MXNA link

Tweets



    Tags

    Other blogs I like...

    Black Pepper Software Go to 'Black Pepper Software'

    Eismann-sf Go to 'eismann-sf'

    Ted On Flex Go to 'Ted On Flash'

    Galleries

    RSS2.0 Atom

    Meetups:

    Not signed in
    Sign in

    Powered by BlogBuilder
    © MMXIV