In order to play your video, you'll need:
- a host for your video;
- modify the height in AS3, since width is fixed to 604 px, so it retains the aspect ratio of your video;
- offset the frame, if your video has thick black borders, so the control panel won't be blocked.
Check the AS3 script and download the sourcefiles below.
Note: the fullscreen function will ONLY work on Flash websites; this website isn't 😛
AS3 Script
//netstream and button code
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
const buffer_time:Number = 2;
ns.client = this;
ns.bufferTime = buffer_time;
var isPlaying:Boolean;
//change the link to your video's url; you'll need a host for your video.
ns.play("https://jourviz.com/wp-content/uploads/2013/03/vc_xia.flv");
isPlaying = true;
pauseClip.visible = false;
var vid:Video = new Video();
vid.attachNetStream(ns);
var vid_frame:MovieClip = new MovieClip ;
vid_frame.addChild(vid);
vid_frame.width = 604;
// important: modify the height, so it matches your video's aspect ratio.
vid_frame.height = 403;
vid_frame.x = 0;
// offset the frame, so your video doesn't block the control panel.
vid_frame.y = -5;
addChildAt(vid_frame, 2);
playPauseBtn.addEventListener(MouseEvent.CLICK, playPause);
pauseClip.addEventListener(MouseEvent.CLICK, pauseClipclick);
function playPause(event:MouseEvent):void
{
if (isPlaying == true)
{
ns.pause();
pauseClip.visible = true;
isPlaying = false;
playPauseBtn.gotoAndStop(2);
}
else
{
ns.resume();
pauseClip.visible = false;
isPlaying = true;
playPauseBtn.gotoAndStop(1);
}
}
function pauseClipclick(event:MouseEvent):void
{
ns.resume();
pauseClip.visible = false;
isPlaying = true;
playPauseBtn.gotoAndStop(1);
}
var meta = new Object ;
function onMetaData(infoObject:Object):void
{
var key:String;
for (key in infoObject)
{
trace(key + ": " + infoObject[key]);
}
meta = infoObject;
var durationSecs:Number = Math.floor(meta.duration);
var durationMins:Number = Math.floor(durationSecs / 60);
durationMins %= 60;
durationSecs %= 60;
var durSecsDisplay:String = "";
var durMinsDisplay:String = "";
if (durationMins < 10)
{
durMinsDisplay = "0" + durationMins;
}
else
{
durMinsDisplay = "" + durationMins;
}
if (durationSecs < 10)
{
durSecsDisplay = "0" + durationSecs;
}
else
{
durSecsDisplay = "" + durationSecs;
}
duration_txt.text = durMinsDisplay + ":" + durSecsDisplay;
}
var t:Timer = new Timer(1000);
t.addEventListener(TimerEvent.TIMER, onTick);
t.start();
function onTick(event:TimerEvent):void
{
var nsSecs:Number = Math.floor(ns.time);
var nsMins:Number = Math.floor(nsSecs / 60);
nsMins %= 60;
nsSecs %= 60;
var nsSecsDisplay:String = "";
var nsMinsDisplay:String = "";
if (nsMins < 10)
{
nsMinsDisplay = "0" + nsMins;
}
else
{
nsMinsDisplay = "" + nsMins;
}
if (nsSecs < 10)
{
nsSecsDisplay = "0" + nsSecs;
}
else
{
nsSecsDisplay = "" + nsSecs;
}
time_txt.text = nsMinsDisplay + ":" + nsSecsDisplay;
videoScrubber.positionBar.width = ns.time / meta.duration * 300;
videoScrubber.follower.x = videoScrubber.positionBar.width;
var loadedPercent:uint = 100 * (ns.bytesLoaded / ns.bytesTotal);
videoScrubber.loadedProgressBar.width = loadedPercent * 3;
if (duration_txt.text == time_txt.text)
{
ns.pause();
ns.seek(0);
playPauseBtn.play();
}
}
// fullscreen code (only works on flash website).
var screenCheck:Boolean = false;
function fullScreenUP(event:MouseEvent):void
{
if (screenCheck == false)
{
stage.displayState = StageDisplayState.FULL_SCREEN;
screenCheck = true;
}
else
{
stage.displayState = StageDisplayState.NORMAL;
screenCheck = false;
}
}
fullScreenBtn.addEventListener(MouseEvent.CLICK, fullScreenUP);
//volume control code
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void
{
var volumeTransform:SoundTransform;
var volumeLevel = ns.soundTransform;
var newLevel:Number = (volumeSlider.knob.x) / -100;
volumeLevel.volume = newLevel;
ns.soundTransform = volumeLevel;
volumeSlider.volumeLightBar.width = volumeSlider.knob.x;
}
var isDragging:Boolean;
videoScrubber.ghostKnob.visible = false;
var scrubberBounds = new Rectangle(0,videoScrubber.ghostKnob.y,videoScrubber.scrubberRect.width,0);
videoScrubber.addEventListener(MouseEvent.MOUSE_DOWN, dragScrub);
stage.addEventListener(MouseEvent.MOUSE_UP, dropScrub);
function dragScrub(evt:Event):void
{
videoScrubber.ghostKnob.startDrag(true,scrubberBounds);
videoScrubber.ghostKnob.visible = true;
isDragging = true;
}
function dropScrub(evt:Event):void
{
if (isDragging == true)
{
stopDrag();
var fullTime:int = Math.floor(meta.duration);
var newPos:Number = fullTime / 100000 * Math.floor(videoScrubber.ghostKnob.x * 1000) / 3;
ns.seek(newPos);
isDragging = false;
videoScrubber.ghostKnob.visible = false;
}
else
{
isDragging = false;
videoScrubber.ghostKnob.visible = false;
}
}