Posts Tagged Flash
Here’s something that’s been around for a while that I didn’t learn about until just recently.
flash.system.capabilities.playerType property can be used to tell whether you’re running in the browser, a standalone player, or the Flash IDE. It returns the following values (from Adobe’s documentation):
- “ActiveX” for the Flash Player ActiveX control used by Microsoft Internet Explorer
- “Desktop” for the Adobe AIR runtime (except for SWF content loaded by an HTML page, which has Capabilities.playerType set to “PlugIn”)
- “External” for the external Flash Player or in test mode
- “PlugIn” for the Flash Player browser plug-in (and for SWF content loaded by an HTML page in an AIR application)
- “StandAlone” for the stand-alone Flash Player
Simply check for
(flash.system.capabilities.playerType == "ActiveX" || flash.system.capabilities.playerType == "PlugIn") and you’ll know you’re in a browser.
By now some of you are probably familiar with Crash Flash CS4’s bad crashing habit.
The majority of these crashes can be fixed with the 10.0.2 Hotfix, but I was consistently seeing one that the update didn’t fix.
On Mac OS 10.5.8, with Flash CS4 10.0.2, Flash would crash anytime I tried to add a custom component I had built and put in the Components library. I have been developing and using this component for almost 4 years, and had never seen this problem before.
I tried every fix that Google had to offer, including dumping fonts, resetting flash, deleting preferences, re-building the component, and nothing worked. Every time I tried to add that component to my Flash file, it would crash without fail. (Or maybe with fail, since it was, after all, crashing….)
I was going through everything, trying to figure out what the problem could possibly be, and I noticed that in the component’s FLA file, there was an entry that was nothing but a period underneath the other folder locations.
Removing that period and re-exporting the SWC solved the crash problem.
These are the things I could do without.
For the past couple of months, I have been working on a SHOUTCast player app in AIR. When I signed on to do the project, I had absolutely no idea that playing SHOUTCast streams in Flash is a Herculean task. It seems there’s this nagging little memory leak related to Flash loading a never-ending audio stream. Flash doesn’t release the memory for the audio already played, and eventually that audio data just builds and builds and builds until your CPU or memory maxes out. So far, I have found little to nothing in the form of a nice quick solution to this.
That being said, perhaps the most viable current solution was posted at MadArco’s DevBlog . It basically entails streaming the audio for 20-30 minutes, then recreating the audio stream in a new variable, and crossfading the two streams, at which point the original can be released from memory and garbage-collected. It’s a nice idea, but in CS3, after the first couple of swaps, I lost sound altogether, and this problem re-occured no matter which “swapping” method I attempted. MadArco’s solution is in AS2, and perhaps I lost something along the way while attempting to convert it to AS3, or perhaps AS3 isn’t able to handle this particular method.
There’s also a nice explanation of the “swapping” concept here.
So, after even more research (by “research” I mean thinking of new ways to search for a solution in Google) I found a post on FlashBrighton about generating audio and PCM wave data. I also found this on ActionScript.org, about using PHP to create a socket connection to read ID3 tags.
See where I’m going with this?
I’m proposing an all-in-one memory-leak-and-ID3-problem fix ShoutCast solution for Flash. Here’s my thoughts on it so far:
1.) Use Socket for getting the ID3 data, and, if possible, getting the stream as well.
2.) Use the FlashBrighton wave-data solution to create the audio from the ByteArray returned by the MP3 stream. This is possible using the URLStream class.
3.) Distribute it as a component or nice reusable class in order to allow beginners to use it easily.
I made some attempts at this yesterday, but the bytecode stuff is way over my head. If anyone has any input, or would like to have a go at this, please leave a comment and let me know what you think!