flash. AS3. Save NetStream to a local file? - actionscript-3

I want to ask how to save video and audio content that I'm loading from some site through a NetStream as an FLV file.
Is there any possible way to do this?
var ns:NetStream = new NetStream(nc);
ns.play('http://somefile.com/file.flv');
var file:FileReference=new FileReference();
**ns.doSomething(file); /// ???**
file.save(data,"flvfile.flv");

I don't think you can do this with NetStream - it doesn't necessarily hold the entire file at any one time.
Why not just point the file reference to 'http://somefile.com/file.flv' - open that, then grab the data from it and save that with another reference once it has completed downloading? You can either run the NS in parallel as a separate operation, or open the NS from the local disc once it has finished downloading.
There's a good answer regarding downloading directly using a FileReference, and the gotchas it involves, here: Flex 3 file download - Without URLRequest

Related

Is there a way to force a browser to not use a .swf file from cache? From within the .swf file itself?

So I have a .SWF file, there are several people I know calling the .SWF file directly from my server onto their page.
I need to do some maintenance on the .SWF and wanted to replace the current SWF file with one that just says "under maintenance". I know there are ways to do it via html/php but I do not have access to the html/php code the other people are using on their servers to call my .swf file.
I plan to name the .swf file with the same exact name, so it doesn't break for the other people linking to my .swf file from their website.. but my concern is that their users will show the a cached version of the .swf file instead of my new .swf file.
Is there actionscript or anything I can put in the .swf so that it prevents the users on the other site from using a cached version?
Thank you.
If people are loading the SWF file directly, the only thing you can do is replace it by a polite loader.
This new structure would be:
a new SWF with the same new from the previous and rename the original one.
this new "main" file would load the original one appending new Date().getTime() to the end of the file name.
loader.load(new URLRequest('myOriginal.swf?k='+new Date().getTime()));
That should work.
You can reduce the caching period for .swf files via an .htaccess rule. For your purposes, reduce it to 1 hour or less. That will force all the newly requested swf files to be redownloaded.
When you're finished with maintenance, remove the rule or increase the caching period.

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" );

Flex URLLoader Upload - Determinate Progress Bar?

My application asks the user to select files for upload using a FileReference / FileReferenceList. The client then compresses the File data and uses URLLoader to upload the contents of the file.
One problem with the URLLoader is that the progress event does not get triggered for uploads. How do I track the upload progress? I am unable to create a FileReference for the newly compressed ZIP ByteArray.
-- Sri
Given the situation of Flex / Flash APIs, the answer is "not possible"

Converting SWF into GIF file

I have a flash file where I load a remote SWF file into my own. Now what I want to do is convert that remote SWF file into a GIF that I can save onto my server.
The remote file is a SWF that has a variable amount of frames, and I somehow need to be able to figure out the amount of frames (I presume), and take a snapshot (picture) of every frame, to turn the taken pictures into a GIF file. That's what I THINK has to be done, however I have no idea if it's even possible to take pictures/snapshots of remote SWF files.
I need some serious suggestions on how I could get this working. I'm a serious Flash newbie, and anything would help.
Trying to capture stage area using BitmapData
var bmd:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
bmd.draw(stage);
And this should help you creating the animated GIF:
http://www.bytearray.org/?p=93
You can use the totalFrames property to see how many frames there are and loop through them. You can draw the frames into a BitmapData object.

ActionScript: How read only part of local file?

How read only part of local file? So that not to load the whole file into memory.
If you are using AIR you can use the readBytes() method of the FileStream API to specify an offset of the file where you want to start reading.
For a SWF that is running in the browser, the only method in the Flash Player 10 is the load() method of the FileReference class and that one doesn't allow you to specify an offset.