Flash AS 3.0 custom video player code
Primary tabs
Finally, after a week of trawling forums, running traces and generally stumbling around in the dark, I've finally got my code for a working custom video player. For anyone who is interested, here it is. Next to get the scrubber bar to scrub...
stop();
var videoInterval = setInterval(videoStatus, 100);
var amoundLoaded:Number;
var duration:Number
var playTime:Number
//if someone clicks back to home button, do just that.
mainBtn.addEventListener (MouseEvent.CLICK, returnHome);
function returnHome (e:MouseEvent)
{
ns.pause();
gotoAndStop("main");
}
profilesMC.visible = false;//turn off visibility of profiles when playing video
var nc:NetConnection = new NetConnection();//this establishes a connection to the internet
nc.connect(null);//this tells Flash that this isn't a Flash Communication Server project
var pauseVid:Boolean = new Boolean(); //setting up the play/pause control
pauseVid = false;//initial parameter is that video is not initially paused.
var ns:NetStream = new NetStream(nc);
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatusEvent);
function onStatusEvent(stat:Object):void
{
if (stat.info.code == "NetStream.Buffer.Full") {
bufferClip.visible = false;
}
if (stat.info.code == "NetStream.Buffer.Empty") {
bufferClip.visible = true;
}
}
var meta:Object = new Object();
meta.onMetaData = function (meta:Object)
{
duration = meta.duration;
}
ns.client = meta;
theVideo.attachNetStream(ns);
ns.play(vidLink);
rewindBtn.addEventListener (MouseEvent.MOUSE_DOWN, rewindVideo);
function rewindVideo (e:Event){
ns.seek(0);
};
playBtn.addEventListener (MouseEvent.MOUSE_DOWN, playPauseVideo);
function playPauseVideo (e:Event):void
{
if (pauseVid == false){
pauseVid = true;
playTime = ns.time;
ns.pause();
}
else{
pauseVid = false;
ns.resume();
}
}
function videoStatus() {
amountLoaded = meta.bytesLoaded/ns.bytesTotal;
loader.loadbar.width = amountLoaded*211.9;
//211.9 px is the width of the loaderbar
loader.scrub.x = (ns.time/duration)*211.9;