Embedding binary video data in a swf file

2019-01-25 22:11发布

问题:

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?

回答1:

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


回答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.



回答3:

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.



回答4:

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 ...



回答5:

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!