Embedding binary video data in a swf file
Asked Answered
E

5

3

Is it possible to play video from data that has been embedded in a swf at compile time (with the [Embed] metatag)?

The "Import Video->Embed" feature provided by Flash CS3 etc. is not acceptable because it has many severe limitations (including sound synchronization issues, a maximum number of frames, and other caveats)

I'm interested in being able to bundle flv video data in a swf (along with other assets), which will be played by an AIR application.

I don't think it can be done. Anyone disagree?

Entitle answered 13/10, 2008 at 21:19 Comment(0)
S
7

As long as your video is an FLV, then the answer is yes - you can use NetStream.appendBytes() to play the embedded ByteArray:

public class Main extends MovieClip
{
    [Embed(source="sample.flv", mimeType="application/octet-stream")]
    private var SampleVideo:Class;

    public function Main():void 
    {
        var video:Video = new Video(320, 240);
        addChild(video);

        var netConnection:NetConnection = new NetConnection();
        netConnection.connect(null);
        var netStream:NetStream = new NetStream(netConnection);
        netStream.client = {};
        video.attachNetStream(netStream);

        var byteArray:ByteArray = new SampleVideo();
        netStream.play(null);
        netStream.appendBytes(byteArray);
    }
}
Sainted answered 27/3, 2012 at 9:47 Comment(1)
Wow! And since FP 10.1! How did I miss that?! Cheers!Entitle
P
2

You can import a flv into a swf file using the Flash IDE - I've done that before. You can drop it onto the timeline of a MovieClip just like a sound and then drop that movieclip onto the stage for it to play. In Flash CS3 do File>Import>Import Video and select the flv. Choose the video and then on the next stop of the wizard choose "Embed ..... ", Here is a link to an Adobe Developer center article on embedding flvs into swfs.

I have not done so myself, but I can see no reason why you could access the flv from the library of a loaded swf.

FYI: It looks like this was a bug that was deferred. It doesn't look like Adobe currently allows embedding using the Embed meta tag. Here is a forum post on the issue and a link to the bug tracker.

Pernod answered 13/10, 2008 at 21:41 Comment(2)
Unfortunately that approach has a lot of caveats which I can't live with. The biggest one is the sound synchronization issue, but there are also framecount restrictions and other misc limitations. I've updated the question. Thanks for answering!Entitle
Thanks for those links James, especially the kirupa.com thread. Makes me feel less insane.Entitle
N
1

It's possible to embed video into SWFs with the Flash IDE but it's not a very good option:

"Playback is limited to simple play and stop commands, and the video framerate must match that of the host movie, an important consideration that will require authoring for the lowest-common-denominator download speed."

"The biggest limitations to embedded video are movies having a maximum of 16,000 frames and audio sync cannot be maintained beyond about two minutes."

Those quotes are from this article. It's a bit old but as far as I know, what is said there about embedding video still holds true.

Nonsectarian answered 14/10, 2008 at 15:45 Comment(1)
That's a very good point. I know the "Import Video->Embed" feature of Flash CS3, but it's not an acceptable solution for those reasons. I'm looking out for another way to embed video. I was imagining something like instantiating an [Embed]ed class and passing it to the video player.Entitle
E
0

Oh yeah, so apparently you can embed binary data in a swf using the Embed meta tag.

[Embed(
    source="local_data_file.flv",
    mimeType="application/octet-stream") ]
private static var __FlvClass123:Class;
protected static var flvData:ByteArray = new __FlvClass123();

Whether you can playback embedded video from a ByteArray or not is not something I cannot answer one way or another at this stage ...

Entitle answered 25/3, 2010 at 20:39 Comment(0)
B
0

just had the same problem and searched for a more "flex"ible solution. seems these Days dynamic embedding works perfectly simple:

public function loadSWF(){

 var _assetLdr:Loader;
_assetLdr = new Loader();
_assetLdr.load(new URLRequest("1.swf"));
_assetLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, this.handleComplete);
addChild(_assetLdr); 
}


public function handleComplete(event:Event):void {

    trace("complete");
    var loaderInfo:LoaderInfo=event.target as LoaderInfo;
    var content:MovieClip = loaderInfo.loader.content as MovieClip;
    addChild(content);

}

Note: Check the screen offsets within the library.swf. In my case they were messed up, so it simply displayed offscreen. (ThankGodForCoffee) Have a nice Day!

Bopp answered 31/5, 2018 at 4:45 Comment(2)
Woah. You say "these days"? Flash still ... like... exists? You're blowing my mind!Entitle
Also, my question actually stipulated embedding, whereas this solution is a runtime download of the movie file, unless I'm missing something.Entitle

© 2022 - 2024 — McMap. All rights reserved.