I wrote a little swf Container which should upload a video file and play it. I followed the official Adobe documentation and the video played smoothly.
Subsequently, I added a few ExternalInterface API callbacks to pause, play, and resume the video, they all work fine. There is only one very unpleasant problem: I can not get information about the current state of the video. Neither a call through the javascript function, nor an internal call in the swf file provide the correct information. I worked a little on this and did not find any information about this problem.
Here's the source code for 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':
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
{
}
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();
(flv mp4), URL-, . . .