AS3 Air — Check a Zip to get Audio File - actionscript-3

I have a problematic situation that I wish to expose you because it contains some opposites constraints. Maybe someone will have an idea on how to unlock my problem.
I'm going to make a mobile application with ActionScript 3 and Air for iOS and Android. This application has to download zip file which it uses to display text, bitmap and sound.
This last one is the problem.
After some research, one of the best way I found to check a zip file is FZip, but it allows us to get data from zip on a ByteArray form. And a Sound can't be converted from ByteArray. ( That's what a lots of results about it appear to say. )
One of the solution proposed is to put the ByteArray of a sound and put it in a SWF. Then take the SWF from the zip to get the Sound.
I can't do that because this zip will be uploaded from a admin interface used by anybody. I can't force them to use Flash.
I have few potential direction where I ask for your advices :
• Use Code or Native Extension ( iOS and Android ) to check a zip without files read in ByteArray
• Convert a ByteArray into Sound without have to pass it in a SWF
• Dynamicly create a SWF with the ByteArray of a Sound
• In the last possibility, another way to drag and download few files together which can be consulted in another format than ByteArray ( Like a iOS Bundle but with android too )
Thanks a lot to help me,

You can simply write the ByteArray on a local mp3 (or mp4) file and then play it, to write a ByteArray to file see documentation here.

Related

ActionScript3 - Saving objects created when application is running

I made an editor that allows to create some custom space ships for game I'm making.
This editor is meant for the player and his ships are saved in SharedObject without a problem.
What i would like to do is to use the editor to create some ships for enemies and use them later when designing levels.
I was thinking about writing the Ship object to ByteArray and than tracing them so i can copy and paste them to code and read them back to object but this does not seem to work since what i get from tracing a ByteArray is only class name and few undefined symbols that i can't even paste here.
The standard trace panel in flash is text based, therefore no bytes can be output properly (ByteArray).
I'm not pretty sure what are the types of objects you need to store, but you can do two things:
Save ByteArray to UTF8 external file; then read it back to ByteArray, and you're on the road again
if you need to trace them out, Base64 encode them (simple but powerful class here: https://gist.github.com/burakkirkil/4051420)

Converting Mpeg file to flv and simultaneously playing the converted file in flash cs3 using as3

I have an mpg file which I want to convert to flv format, but I have a requirement that while converting the mpg file, I also have to simultaneously play the converted flv file in the flash cs3. How to do it? I am using cs3 and as3.
If you want to convert your files programmaticly then use ffmpeg. This is a commandline tool which can convert video files to nearly everything. You have to execute ffmpeg with the correct params and wait until the video is ready. This works only on serverside. Means the flash client loads up the video file to the server. There it gets converted. You can execute ffmpeg with any serverside language like php.
Sadly I have no idea if it is possible to watch the video while converting. I think not but maybe someone else knows more.

How to join multiple mp3s into one downloadable mp3 file in Flash AS3?

I have a couple of short mp3 files that the user can reorganize on a timeline. After that, I want to save the result as one mp3 file, combining six short ones.
In other projects I have done microphone recording, compressing to mp3 using the alchemy ShineMP3Encoder, and saving that as a file.
I see at least two approaches:
Extracting all ByteArray data from the loaded Sound objects,
concatenating that in a new ByteArray and compressing that with
Shine. However the ByteArray from Sound.extract doesn't seem to be
compatible with the encoder, telling me "Error : Input not a
MS-RIFF file"
Somehow combining the raw MP3 files without the need of decoding
and encoding. But that would mean having to strip off file header info
and such.
If impossible or very inefficient in Flash, I would consider a server side solution in PHP. So if that would be easy, please let me know.
Thanks!
Do these need to be physically combined into a single file; ie does the Flash need to actually generate a single MP3? Or just played back to the user as if they were one long file?
Flash does not have any built-in capacity to encode MP3s, though various I believe Flash Media Servers have that capacity (Red5, etc.). Actually, on exploration, here is a link to a guy who claims he has technology that will allow you to record an MP3 client-side, though it appears to be more for audio recordings from a built-in mic:
http://fms.denniehoopingarner.com/
Perhaps you could work with him to alter the code to work with existing sound files and generate a new one. Otherwise, you will probably need to do it with some fancy server-side footwork.
It turns out it is in fact easy to combine multiple mp3 files. You can just concatenate their raw data and save it out as a new mp3 file. A few conditions apply:
Make sure all compression settings are identical and non-dynamic. Bitrate, frequency, stereo/mono, etc.
The end result's length indicated by your OS or an mp3 player might be wrong, and show the length of the first segment only. This is header-data. Most players, including Flash, will just play the whole file though, so in most situations this might not be a problem.
In this example I'm using Greensock's LoaderMax library. DataLoader is the specific loader type you want to use (should be binary by default). *Note that I'm using the url as the name to identify the loader later, and some *_variables* need to be declared as class members*
Of course you could use the native way or a different library to load your files too.
for each ( var mp3FileURL : String in _mp3FileURLs )
{
var loader : DataLoader = new DataLoader( mp3FileURL, mp3FileURL ) );
_preloadQueue.append( loader );
}
When loading the queue is complete, you can start processing the data from the loaders.
_audioEditMP3 = new ByteArray();
for each ( var mp3FileURL : String in _mp3FileURLs )
{
var content : * = _preloadQueue.getContent( mp3FileURL );
_audioEditMP3.writeBytes( content );
}
You are now ready to save the file!
var file : FileReference = new FileReference();
file.save( _audioEditMP3, "myAudioCompilation.mp3" );

Code-generated SWF to FLV

I need to convert a swf movie that is created entirely through code (with the help of TweenLite) to a .flv format. The issue here is that I need to 1) Do this as a batch process, and that 2) since the swf is entirely generated by code it only has 1 frame and as such normal conversions like from CS5.5 to to the .avi format give me just 1 frame in the resulting video format. Is there a free converter out there that can get past the fact that my video is technically only 1 frame long and can handle batch jobs? Thanks for all your help
Sounds like you could implement a JSFL extension if you have a copy of Adobe Flash or a trial from their site. It basically adds a command to publish multiple folders and sub folders.
http://www.adobe.com/cfusion/exchange/index.cfm?event=extensionDetail&loc=en_us&extid=1021887

AS3 - AIR - From a swf path file to a ByteArray

I am coding an AIR application.
I've got directly a path of a swf file (because it was stored in a xml file).
Do yo know if it is possible to get the ByteArray from this file ?
I know that FileReference do that very well, but this class need a select event. But it isn't my case because I've allready got my path.
Thanks a lot for your answers !
In AIR, you can read/write files directly using flash.filesystem.File and flash.filesystem.FileStream.
See, for example, this article.
however you can load it with URLStream and get a ByteArray with URLStream.readBytes()