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...
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.
Check these tutorials
http://gotoandlearn.com/play.php?id=46
http://gotoandlearn.com/play.php?id=129
I think that if the video is embed in a MovieClip as you did it , the only behavior you can expect is what you're getting at the moment. It will play but you won't have any control over it.
Why do you insist on embedding it? It will make your file bigger and the video won't play until the swf has completely loaded. It's a short video but it still will take far longer than accessing it via progressive download.
Admittedly the second tutorial doesn't have much relevance but why not add it , it gives you more scope on how to deal with media in Flash. OSMF is a new framework and I think it makes sense to know about it.
精彩评论