Search code examples
actionscript-3videoflashembedmovieclip

AS3 - Embedded SWF video shows totalFrames == 0


I've got this 1 minute long movie that I want to compile into an AS3 project. The movie started out in MOV format, so I used FFMpeg to convert it to FLV, then again with FFMpeg from FLV to SWF.

I'm embedding this movie into the AS3 binary by using Embed metadata:

[Embed(source="1.swf")]
private var _Vid:Class;

I've got a container Sprite that this movie gets added to. Before it's added in, I cast the embedded movie as a MovieClip:

var vid:Object = new _Vid();
return vid as MovieClip;

When I add the resulting movie clip to the stage, it begins playing immediately and seems to play fine. However, when I check the totalFrames property of the movie clip, it returns 0. And the movie clip doesn't seem to respond to calls to stop or gotoAndStop.

I get this same behavior from embedding the movie into an SWF in the Flash IDE then embedding the result in the same manner, so it seems something is out of whack with the way I'm adding it to the stage. Any thoughts?

EDIT: As a requirement of the product, the as3 movie cannot load the video from an external file. It must be compiled in, so the resultant .swf that does the playing can operate completely on its own without having to rely on other external files.

EDIT 2: Upon further inspection, the MovieClip instance that results from:

[Embed(source="1.swf")]
private var _Vid:Class;
var vid:Object = new _Vid();
return vid as MovieClip;

has one child object which is of class Loader, and that child has no children. I tried casting the child directly as MovieClip but to no avail.

EDIT 3: From what I'm reading here and here, the 10.1 api for the NetStream object exposes a method called appendBytes. I still need to look further into this, but I could embed the .flv file as an octet stream and feed the bytes manually to the Net Stream object to play the video. I'll post the result of my tests in a few...


Solution

  • I ended up embedding the video as binary data:

    [Embed(source="1004.flv", mimeType="application/octet-stream")]
    

    Then using NetStream.appendBytes() to feed the video to a NetStream that's hooked up to a Video object. This works beautifully, and the NetStream can be paused and replayed.