I wrote a little swf Container which should load a video file and playback it. I followed the official Adobe documentation and the video plays smoothly.
Afterwards I added some ExternalInterface API Callbacks for pausing, playing and resuming the video, all of them are working fine. There's just one very annoying issue here: I am not able to get information about the current state of the video. Neither a call via a javascript function nor an internal call in the swf file deliver some correct information. I did some digging into this and found no information about this issue.
Here's the source code of the swf file and an example html for embedding it:
HTML
<object id="ie-video" width="1280" height="720" type="application/x-shockwave-flash" data="flash_container.swf">
<param name="movie" value="flash_container.swf" />
<param name="wmode" value="opaque" />
<param name="flashvars" value="vid_name=video&objWidth=1280&objHeight=720" />
<param name="AllowScriptAccess" value="always">
</object>
SWF
import flash.external.*;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.net.NetStream;
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters.vid_name;
var objWidth:int = LoaderInfo(this.root.loaderInfo).parameters.objWidth;
var objHeight:int = LoaderInfo(this.root.loaderInfo).parameters.objHeight;
var videoPath:String = paramObj.toString() + ".flv";
var nc:NetConnection = new NetConnection();
nc.connect(null);
var vid:Video = new Video(objWidth, objHeight);
addChild(vid);
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
var isVideoPlaying:Boolean;
var outputText:TextField = new TextField();
outputText.x = 10;
outputText.y = 10;
outputText.background = true;
outputText.autoSize = TextFieldAutoSize.LEFT;
addChild(outputText);
function netStatusHandler(event:NetStatusEvent):void
{
switch (event.info.code) {
case 'NetStream.Play.Start':
//ExternalInterface.call("fadeInPack()");
outputText.text = event.info.code.toString();
break;
case 'NetStream.Play.Stop':
outputText.text = event.info.code.toString();
break;
case "NetConnection.Connect.Success":
outputText.text = event.info.code.toString();
break;
case "NetStream.Play.StreamNotFound":
trace("Unable to locate video");
break;
}
}
function asyncErrorHandler(event:AsyncErrorEvent):void
{
//ignore error
}
function videoPause() {
ns.pause();
isVideoPlaying = false;
}
function videoResume() {
ns.resume();
isVideoPlaying = true;
}
function getCurrentTime() {
outputText.text = ns.info.toString();
return ns.info;
}
function videoTogglePause() {
ns.togglePause();
isVideoPlaying = !isVideoPlaying;
}
function videoIsPlaying() {
return isVideoPlaying;
}
function videoPlay() {
isVideoPlaying = true;
vid.attachNetStream(ns);
ns.play(videoPath);
outputText.text = ns.info.toString();
}
ExternalInterface.addCallback("videoPause",videoPause);
ExternalInterface.addCallback("videoResume", videoResume);
ExternalInterface.addCallback("getCurrentTime", getCurrentTime);
ExternalInterface.addCallback("togglePause", videoTogglePause);
ExternalInterface.addCallback("videoIsPlaying", videoIsPlaying);
ExternalInterface.addCallback("videoPlay", videoPlay);
Javascript for ExternalApi Calls
element = document.getElementById('ie-video');
element.videoPlay();
element.getCurrentTime();
I tried different video formats (flv and mp4), access through local filesystem or url and nothing seems to work. Even the internal prints of the info object aren't giving any information. Any help is appreciated.