Archive for the 'Uncategorized' Category

Monday, December 14th, 2009

Playing mp3 streaming audio in Flash player 10 is a resource hog.

You can play streaming mp3 audio in Flash player using the Sound object. However, there are some serious problems with this, which I feel we should make clear, since Chris’s recent outburst post did not really explain the core problem which we still face, which we have worked around in a rather unsatisfactory way. The solution works but still suffers from some unfortunate problems which become apparent on lower spec machines (and by this I mean Pentium 4 generation machines).

First and foremost, and this applies to both the AS2 + AS3 Sound objects, playing streaming audio has the effect of consuming an ever growing amount of memory. The memory allocated to the audio which has been played already is never deallocated, other than by stopping the stream. For this reason, all Flash based stream players will either bring the machine to its knees in a short time, or will require a regular covert reconnect every 10-20 minutes, which obviously causes a glitch in the music, however cleverly it is done (we do make a great effort to do it as subtly as possible).

We originally set out to write the Flash part of radiotuna.com in AS3. However, the AS3 Sound object behaves rather differently to the old AS2 Sound object: To be precise, it does not deal with mid-stream bitrate changes. This means that should the bitrate change during the course of playing the stream (which it frequently does with internet radio broadcasts, usually after an intro, or during a ‘jingle’), the sound goes very very BAD. It either sounds like its speeded up, or broken up in to chunks, since its using the bitrate declared at the start of the stream and ignoring the bitrate change embedded in the stream. This was completely unacceptable, since so many radio stations change bitrate after an initial jingle.

The old AS2 Sound object deals correctly with bitrate changes, and for this reason we chose to rewrite the stream player part of the site in AS2. However, what soon became apparent was that along with the rising memory usage, we were now seeing a linear rise in processor usage as the stream progressed, meaning that on a Pentium 4 machine the single processor was at 100% within 10-20 minutes depending on the bitrate. This of course made the machine unresponsive, again completely unacceptable. The solution of course is the same, but a sad state of affairs nonetheless.

Hopefully Adobe can address these serious problems, even if it means working with the browser vendors on how never-ending downloads are managed between browser and player.

I too would like this and other bugs in the Flash player ironed out as a priority, before introducing any more new features. New features are great, and I am particularly impressed with the iPhone announcement, but one reason I am writing this post is that since compiling for iPhone will only be for AS3, our solution will not apply. Adobe, please make sure that the AS3 Sound object respects midstream bitrate changes in future releases, and when compiled for iPhone.

Monday, July 27th, 2009

Silverlight 3 font rendering not quite there yet

After saying yesterday that Silverlight 3 has Cleartype, I must now point out that while this is true, after looking at a few samples today, as well as this font rendering comparison, the quality of rendering is not on a par with the standard Windows Cleartype that we are used to. (winforms text in the link above)

This is really disappointing. While its a significant improvement over 2.0, it still has that fuzzy, projected look to it, that to me, and others makes applications feel ‘foreign’ or even ‘fake.’

In the Flash world, we suffered terrible text rendering until the introduction of Saffron a few years ago, which is actually rather good, and although not native, has a crisp and even feel to it.

I honestly think that the lack of native widgets and text rendering has been a major barrier to the psychological acceptance of Flash/Silverlight/Java based applications as ‘real’. Remember the clunky old Swing components, and how they made you feel that ‘this is not the real thing’. :)

Of course, if it’s even better than ‘the real thing’ that’s great, but the difficulty of achieving this with a one-size fits all approach should not be underestimated.

As children, we learn to distinguish toys from real tools by their appearance, and this may account for the lack of credibility that non-native (looking) applications have. An enormous effort has been made to get native UI into Java, so I can’t be the only one who thinks this. However, I certainly don’t agree with Jeff’s preference for IE7, a program that, to me, is an abomination, and only exists to test the patience of web developers.

Sunday, July 26th, 2009

Are these bugs ever going to be fixed?

A couple of years ago I had the dubious pleasure of working with WSSE and the as3corelib library which implements some of the required functionality for communicating with WSSE enhanced web services in AS3. I was accessing a .NET application which exposed such web services and ‘consuming’ them with Flex. After hacking the code in this library a little so that it actually did what I needed (generating WSSE security headers for the SOAP messages), it turned out something was very much amiss. All the data getting sent looked good, but requests were rejected with an ‘InvalidSecurityToken’ or somesuch exception. After a lot of detective work, it turned out that this bug was squarely to blame.

In getUsernameToken, the nonce is base64-encoded. This encoded value is
then used in determining the password digest. This is not according to the
WS-Security UsernameToken specification: the password digest is based on
the unencoded nonce value.

from http://code.google.com/p/as3corelib/issues/detail?id=25

Now the fix for this is truly trivial, moving a single line of code in getUsernameToken , however I would forgive anyone facing this problem for simply giving up, the problem is so obscure (and unlikely).

Corrected code
var password64:String = getBase64Digest(nonce, created, password);
nonce = base64Encode(nonce);

Original incorrect code
nonce = base64Encode(nonce);
var password64:String = getBase64Digest(nonce,created,password);

TWO YEARS have passed since this bug was reported. It’s status is still ‘New’. It still doesn’t even have an owner. There is a patch for it though, which was submitted more than six months ago now, but still not has found its way into the trunk.

I bring this up now because I recently had the pleasure of sharing this esoteric information with another developer who was facing similar issues.

The thing is, how did this code ever end up being published? It is simply wrong. Have any of the orginal developers actually tested this code against a real implementation of WSSE? I don’t see how it could ever have worked, or how it ended up being published, and with the fix yet to be rolled into the trunk, every developer who has ever called the getUsernameToken method must be scratching their head.

Of course, I know that bugs can and do find their way into release software, it’s a fact of life. Hey, maybe it was a slip of the mouse at the last minute :) But show stopping bugs that are still there two years after they are reported, I cannot understand.

If you ever work with this library, do read http://code.google.com/p/as3corelib/issues/list because other issues that may also impact on WSSE also have fixes attached there.

Sunday, July 26th, 2009

Silverlight comes of age

As a long time Flash/.NET programmer, Silverlight has always been of interest to me. However, apart from a little pong game we made when it was still WPFE, I’ve never taken the trouble to delve into this new tech too deeply. The main reason has always been that these things tend to be both frustrating and disappointing in their first couple of years of life. APIs change and break your code, and essential features are broken or missing. All in all, developing with a mature platform is much more satisfying and rewarding.

For Silverlight, it was the lack of support for dynamic bitmaps, and the appallingly bad font rendering that screamed ‘Not ready!’ through versions 1 and 2. The look of the text reminded me of Linux windowing systems before they recently got their act together.

In fact, the font rendering was so bad that it sparked discussions such as this and this.

People did come up with some ingenious hacks for the bitmap problem, but really you don’t want to have to do this sort of thing. And as this quote from the Silverlight forums sums up, crappy font rendering is not an option if Silverlight is ever going to compete with Flash.

Fonts look like crap in Silverlight. Doesn’t matter what font I use, if I embed it or what, they look like crap. Even companies like DevExpress, Telerik and Componentone’s samples for their new controls look like crap because of the fonts.

This is just imbarrassingly bad. Is there a way to make them look like they should? Is this going to be fixed?

It sure should be fixed for the final version, cause otherwise Adobe and company are going to laugh you out of the room.

Geminiman

Fortunately MS appears to have understood the concerns here and Silverlight 3 has Cleartype as well as WritableBitmap

Looks like old Silverpants is starting to get with the program. Maybe I should too.

Thursday, August 14th, 2008

Psychedelic mandala in Flash Player 10

Using the new features of Flash Player 10, it is now possible to load files directly from the users drive.
Click anywhere to load your image into the Flash Player, and experience the faster, smoother rendering of Flash Player 10 with this psychedelic mandala we knocked together.

Flash Player 10 release candidate required.

Friday, May 23rd, 2008

Running locally loaded MP3 files through an fx chain

Combining the work in the previous 2 posts gives the following coolness (Flash Player 10 required):

(more…)

Friday, January 18th, 2008

Flex: RangeError 2006 and the re-parenting of UIComponents

I have been working with Flex recently and have found something that for a while foxed me completely. My application would crash when resized suddenly. That is, everything was broken, even buttons were not responding. The exception thrown (rangeError 2006 - index out of bounds) was from deep down in the framework, in the getChildAt method of DisplayObjectContainer, called by mx.core.Container. The root of the callstack showed callLaterDisparcher. Obviously a timing bug of some kind…

After a few experiments I found that this was due to multiple calls of my stage resize handler on the same frame. An obvious fix came to mind, but not a satisfactory one. By only accepting one call per frame the resize handler could be made stable, but this did not sit well. Why should this be necessary? Why should calling the same function twice on the same frame cause such catastrophic failure?

We set out to build a minimal case of the problem. Eventually we discovered the following test case which demonstrates our finding:

You can re-parent a UIComponent without removing it from its parent. But if you do this twice on the same frame, Flex will crash.

Of course, knowing this, the fix is simply to re-parent by removing and then adding. Well worth knowing if you are doing any reparenting.

NB This is different from how DisplayObjectContainer behaves.

Minimal test case

NB This is fixed in Flex 3.

Wednesday, December 12th, 2007

Playing MP3 data using the Flash sound “hack”

A recurrent question that I see after writing the article “How to make actionscript 3 play generated pcm wave data” is how would one do this with MP3 data.

I spent a while hacking around to see if it could be done, and came up with this.

Not much time to write anything about this, but I thought that I should just post up the code. It requires an mp3 called “sample.mp3″ in the “media” folder in order to work. There should be a certain amount of resilience to errors in the MPEG stream.

We’re not opening up comments at the moment, so please post back to the original pcm wave data article if you have any comments.

Sunday, December 9th, 2007

Test all files in a folder

Making use of the FLFile api in Javascript for Flash (JSFL) can be quite handy when dealing with large numbers of files. Here’s a scrap that I have been using to test a folder full of files:


var srcFolder="file:///path/to/a/directory";
var files=FLfile.listFolder( srcFolder , "files" );
for(var i=0;i<files.length;++i)
{
var fileName=files[i];
var fileSuffix=fileName.substr(-4);
if(fileSuffix.toLowerCase()==”.fla”)
{
fl.trace(”testing : “+fileName);
test(srcFolder+”/”+fileName);
}
}
function test(fileName)
{
var doc=fl.openDocument(fileName);
doc.testMovie();
doc.close();
}

Seing as I feel like I’ve written this piece of code about 20 different times, here seems like a good place to drop it for preservation.

Wednesday, December 13th, 2006

Test

This is a test.