# AS2 Vidoe Player

**URL:** <https://forum.kirupa.com/t/as2-vidoe-player/319788>\
**Category:** flash\
**Created:** [March 4, 2011, 9:48am UTC](https://forum.kirupa.com/t/as2-vidoe-player/319788 "2011-03-04T09:48:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vaishakh](https://avatars.discourse-cdn.com/v4/letter/v/48db29/32.png) [@Vaishakh](https://forum.kirupa.com/u/Vaishakh)\
**Post date:** [March 4, 2011, 9:48am UTC](https://forum.kirupa.com/t/as2-vidoe-player/319788/1 "2011-03-04T09:48:35Z")

</div>

Hello guys,

I am just wondering if you could help this for me…

here is the original code which am using for my current player and am in trouble to add new stuffs.

I’d like to see the video preview in my player as of now if i click any video from the list it will appear in the player. When i load the page currently there is no video in the player… can you please help me???

for your concern am pasting the player code, please revert me with updates 😃

/  
// INITITAL SETTINGS  
//  
// Set document stage and width here  
stageW = 800;  
stageH = 600;  
// Set default volume here (percentage)  
defaultVolume = 100;  
// Set default buffer time here (seconds)  
defaultBuffer = 3;  
// Set default gallery here (0 = first gallery)  
galleryID = 0;  
//  
// ORIGINAL VALUES (FOR FULLSCREEN/NORMAL MODE)  
//  
// Control clips  
controls\_mc.originX = controls\_mc.\_x;  
controls\_mc.originY = controls\_mc.\_y;  
controls\_mc.bg\_mc.originWidth = controls\_mc.bg\_mc.\_width;  
controls\_mc.sound\_time\_mc.originX = controls\_mc.sound\_time\_mc.\_x;  
// Video holder  
video\_holder.originX = video\_holder.\_x;  
video\_holder.originY = video\_holder.\_y;  
video\_holder.originWidth = video\_holder.\_width;  
video\_holder.originHeight = video\_holder.\_height;  
// Progress bar  
controls\_mc.progress\_mc.originX = controls\_mc.progress\_mc.\_x;  
controls\_mc.progress\_mc.originWidth = controls\_mc.progress\_mc.\_width;  
//  
// STAGE RESIZE (FOR FULLSCREEN/NORMAL MODE)  
//  
// Normal mode  
objectsNormal = function () {  
// Control clips  
controls\_mc.\_x = controls\_mc.originX;  
controls\_mc.\_y = controls\_mc.originY;  
controls\_mc.bg\_mc.\_width = controls\_mc.bg\_mc.originWidth;  
controls\_mc.sound\_time\_mc.\_x = controls\_mc.sound\_time\_mc.originX;  
// Progress bar  
controls\_mc.progress\_mc.\_width = progress\_mc.originWidth;  
// Video holder  
video\_holder.\_x = video\_holder.originX;  
video\_holder.\_y = video\_holder.originY;  
video\_holder.\_width = video\_holder.originWidth;  
video\_holder.\_height = video\_holder.originHeight;  
// Progress bar  
controls\_mc.progress\_mc.\_width = controls\_mc.progress\_mc.originWidth;  
};  
// Fullscreen mode  
objectsFullscreen = function () {  
// Control clips  
controls\_mc.\_x = Math.round(-(Stage.width-stageW)/2);  
controls\_mc.\_y = Math.round(-(Stage.height-stageH)/2+Stage.height-25);  
controls\_mc.bg\_mc.\_width = Stage.width;  
controls\_mc.sound\_time\_mc.\_x = controls\_mc.bg\_mc.\_width-controls\_mc.sound\_time\_mc.\_width;  
// Video holder  
video\_holder.\_x = Math.round(-(Stage.width-stageW)/2);  
video\_holder.\_y = Math.round(-(Stage.height-stageH)/2);  
video\_holder.\_width = Stage.width;  
video\_holder.\_height = Stage.height-25;  
// Progress bar  
controls\_mc.progress\_mc.\_width = controls\_mc.bg\_mc.\_width-10-controls\_mc.sound\_time\_mc.\_width-controls\_mc.progress\_mc.originX;  
};  
// Stage resize listener  
Stage.scaleMode = “noScale”;  
stageListener = new Object(this);  
Stage.addListener(stageListener);  
alignObjects = function () {  
// Align background  
\_parent.bg.\_width = Stage.width;  
\_parent.bg.\_height = Stage.height;  
\_parent.bg.\_x = -(Stage.width-stageW)/2;  
\_parent.bg.\_y = -(Stage.height-stageH)/2;  
if (fullscreenMode) {  
objectsFullscreen();  
}  
};  
stageListener.onResize = function() {  
alignObjects();  
};  
alignObjects();  
//  
// FULLSCREEN MODE BUTTON  
//  
controls\_mc.sound\_time\_mc.bttnFullscreen.bttn.onPress = function() {  
if (this.\_parent.icon\_mc.\_currentframe == 1) {  
// Go fullscreen  
fullscreenMode = true;  
Stage[“displayState”] = “fullScreen”;  
this.\_parent.icon\_mc.gotoAndStop(2);  
objectsFullscreen();  
this.\_parent.onEnterFrame = function() {  
if (Stage[“displayState”] == “normal” && fullscreenMode) {  
fullscreenMode = false;  
this.icon\_mc.gotoAndStop(1);  
objectsNormal();  
delete this.\_parent.onEnterFrame;  
}  
};  
} else {  
// Go normal  
delete this.\_parent.onEnterFrame;  
fullscreenMode = false;  
Stage[“displayState”] = “normal”;  
this.\_parent.icon\_mc.gotoAndStop(1);  
objectsNormal();  
}  
};  
//  
// LOAD VIDEO STREAM  
//  
// Reset video and controls  
resetVideo = function () {  
durationDisplay = “0:00”;  
controls\_mc.progress\_mc.buffer\_mc.\_xscale = 0;  
controls\_mc.progress\_mc.played\_mc.\_xscale = 0;  
videoEnd = false;  
doPlay();  
};  
resetVideo();  
// Video stream  
var nc:NetConnection = new NetConnection(this);  
nc.connect(null);  
var ns:NetStream = new NetStream(nc);  
ns.setBufferTime(defaultBuffer);  
// Attach video stream  
video\_holder.videoClip.attachVideo(ns);  
// Attach audio stream  
video\_holder.attachAudio(ns);  
video\_holder.videoClip.smoothing = true;  
loadVideo = function () {  
resetVideo();  
ns.play(toLoad);  
ns.onMetaData = function(obj) {  
duration = obj[“duration”];  
var minutes2:Number = Math.round(duration/60);  
var seconds2 = Math.round(duration%60);  
if (seconds2\<10) {  
seconds2 = “0”+seconds2;  
}  
durationDisplay = minutes2+":"+seconds2;  
};  
};  
//  
// THUMB PRESS (LOADS VIDEO)  
//  
\_global.thumbPress = function(obj) {  
toLoad = xmlNode.childNodes[galleryID].childNodes[obj.ID].attributes.VideoClip;  
videoTitle.text = xmlNode.childNodes[galleryID].childNodes[obj.ID].attributes.Title;  
galleryTitle.text = xmlNode.childNodes[galleryID].attributes.Name;  
video\_holder.loaderMC.\_visible = true;  
loadVideo();  
};  
//  
// SOUND CONTROLS  
//  
controls\_mc.sound\_time\_mc.bttnSound.mc\_soundLevel.\_visible = false;  
controls\_mc.sound\_time\_mc.bttnSound.bttn.onRollOver = function() {  
this.\_parent.mc\_soundLevel.\_visible = true;  
};  
controls\_mc.sound\_time\_mc.bttnSound.bttn.onRollOut = controls\_mc.sound\_time\_mc.bttnSound.bttn.onDragOut=function () {  
if (!this.\_parent.mc\_soundLevel.hitTest(\_xmouse, \_ymouse, true)) {  
this.\_parent.mc\_soundLevel.\_visible = false;  
}  
};  
controls\_mc.sound\_time\_mc.bttnSound.mc\_soundLevel.onRollOut = function() {  
this.\_visible = false;  
};  
// Adjust volume on slider press  
var video\_sound:Sound = new Sound(video\_holder);  
video\_sound.setVolume(defaultVolume);  
controls\_mc.sound\_time\_mc.bttnSound.mc\_soundLevel.mc\_bar.\_yscale = defaultVolume;  
controls\_mc.sound\_time\_mc.bttnSound.mc\_soundLevel.onPress = function() {  
controls\_mc.sound\_time\_mc.bttnSound.mc\_soundLevel.onEnterFrame = function() {  
if (this.\_ymouse\<0) {  
volumeTo = 0;  
} else if (this.\_ymouse\>this.bar.\_height) {  
volumeTo = 100;  
} else {  
volumeTo = (this.\_ymouse/this.bar.\_height)_100;  
}  
this.mc\_bar.\_yscale = 100-volumeTo;  
video\_sound.setVolume(100-volumeTo);  
};  
};  
// Adjust volume on slider release  
controls\_mc.sound\_time\_mc.bttnSound.mc\_soundLevel.onRelease = controls\_mc.sound\_time\_mc.bttnSound.mc\_soundLevel.onReleaseOutside=function () {  
delete controls\_mc.sound\_time\_mc.bttnSound.mc\_soundLevel.onEnterFrame;  
this.\_visible = false;  
};  
//  
// PLAY / PAUSE CONTROLS  
//  
// Button functions  
doPlay = function () {  
ns.pause(false);  
controls\_mc.bttnPlay.icon\_mc.gotoAndStop(1);  
};  
doPause = function () {  
ns.pause(true);  
controls\_mc.bttnPlay.icon\_mc.gotoAndStop(2);  
};  
doRestart = function () {  
ns.seek(0);  
controls\_mc.bttnPlay.icon\_mc.gotoAndStop(1);  
ns.pause(false);  
};  
// Play button  
controls\_mc.bttnPlay.bttn.onPress = function() {  
if (controls\_mc.bttnPlay.icon\_mc.\_currentframe == 1) {  
doPause();  
} else {  
if (ns.time\>=duration && duration != undefined) {  
doRestart();  
} else {  
doPlay();  
}  
}  
};  
// Rewind button  
controls\_mc.bttnRewind.bttn.onPress = function() {  
doRestart();  
};  
//  
// PROGRESS BAR CONTROLS  
//  
// Adjust playhead on progress bar press  
controls\_mc.progress\_mc.onPress = function() {  
controls\_mc.progress\_mc.onEnterFrame = function() {  
if ((this.\_xmouse_this.\_xscale)/100\<0) {  
this.percentage = 0;  
} else if ((this.\_xmouse_this.\_xscale)/100\>this.\_width && this.buffer\_mc.\_xscale == 100) {  
this.percentage = 100;  
} else {  
this.percentage = Math.round((this.\_xmouse_this.\_xscale)/100/this.\_width_100);  
}  
ns.pause(true);  
seekTime = this.percentage/100_duration;  
seekTime = Math.round(seekTime_100)/100;  
ns.seek(seekTime);  
};  
};  
// Adjust playhead on progress bar release  
controls\_mc.progress\_mc.onRelease = controls\_mc.progress\_mc.onReleaseOutside=function () {  
if (this.percentage == 100) {  
doPause();  
} else {  
doPlay();  
}  
delete controls\_mc.progress\_mc.onEnterFrame;  
};  
onEnterFrame = function () {  
// Get video stream bytes loaded  
percentage = Math.round(ns.bytesLoaded/ns.bytesTotal_100);  
controls\_mc.progress\_mc.buffer\_mc.\_xscale = percentage;  
// Get video time  
ns\_seconds = ns.time;  
minutes = Math.floor(ns\_seconds/60);  
seconds = Math.floor(ns\_seconds%60);  
if (seconds\<10) {  
seconds = “0”+seconds;  
}  
controls\_mc.sound\_time\_mc.time\_txt.text = minutes+":"+seconds+" / "+durationDisplay;  
// Progress bar position  
if (ns.time\>=duration && duration != undefined) {  
controls\_mc.progress\_mc.played\_mc.\_xscale = 100;  
if (videoEnd == false) {  
controls\_mc.bttnPlay.icon\_mc.gotoAndStop(2);  
videoEnd = true;  
}  
} else {  
controls\_mc.progress\_mc.played\_mc.\_xscale = Math.round(ns.time_100/duration);  
videoEnd = false;  
}  
};  
//  
// BUILD GALLERY  
//  
buildGallery = function () {  
// Reset scroll bar and menu item position  
menu\_mc.bttn\_mc.\_y = 0;  
menu\_mc.scrollBttn.\_y = menu\_mc.scrollBttn.originY;  
// Remove previously created menu items  
num = galleryTotal;  
for (j=0; j\<num; j++) {  
menu\_mc.bttn\_mc[“bttn”+j].removeMovieClip();  
}  
// Get number of items in gallery  
galleryTotal = xmlNode.childNodes[galleryID].childNodes.length;  
for (i=0; i\<galleryTotal; i++) {  
// Build array with XML data  
Thumb_ = xmlNode.childNodes[galleryID].childNodes\*.attributes.Thumb;  
VideoClip\* = xmlNode.childNodes[galleryID].childNodes\*.attributes.VideoClip;  
Title\* = xmlNode.childNodes[galleryID].childNodes\*.attributes.Title;  
Copy\* = xmlNode.childNodes[galleryID].childNodes\*.attributes.Copy;  
// Build meny items  
menu\_mc.bttn\_mc.bttn.duplicateMovieClip(“bttn”+i, i);  
menu\_mc.bttn\_mc[“bttn”+i].ID = i;  
menu\_mc.bttn\_mc[“bttn”+i].\_y = menu\_mc.bttn\_mc.bttn.\_height_i;  
menu\_mc.bttn\_mc[“bttn”+i].holder\_mc.holder.loadMovie(Thumb_);  
menu\_mc.bttn\_mc[“bttn”+i].title\_txt.text = Title\*;  
menu\_mc.bttn\_mc[“bttn”+i].copy\_txt.text = Copy\*;  
}  
// Load first item in current gallery  
select\_mc.selectShow.txt.text = Name[galleryID];  
toLoad = xmlNode.childNodes[galleryID].childNodes[0].attributes.VideoClip;  
videoTitle.text = xmlNode.childNodes[galleryID].childNodes[0].attributes.Title;  
galleryTitle.text = xmlNode.childNodes[galleryID].attributes.Name;  
video\_holder.loaderMC.\_visible = false;  
//loadVideo();  
};  
//  
// LOAD XML  
//  
loadXML = function (loaded) {  
if (loaded) {  
xmlNode = this.firstChild;  
total = xmlNode.childNodes.length;  
Name = [];  
Thumb = [];  
VideoClip = [];  
Title = [];  
Copy = [];  
for (n=0; n\<total; n++) {  
// Get gallery name  
Name[n] = xmlNode.childNodes[n].attributes.Name;  
// Build gallery select menu  
select\_mc.selectBttn\_mc.selectBttn.duplicateMovieClip(“selectBttn”+n, n);  
select\_mc.selectBttn\_mc[“selectBttn”+n].\_y = -select\_mc.selectBttn\_mc.selectBttn.\_height-(select\_mc.selectBttn\_mc.selectBttn.\_height)\*n;  
select\_mc.selectBttn\_mc[“selectBttn”+n].txt\_mc.txt.text = Name[n];  
select\_mc.selectBttn\_mc[“selectBttn”+n].ID = n;  
select\_mc.selectBttn\_mc.selectBttn.\_visible = false;  
}  
buildGallery();  
} else {  
trace(“Error loading XML”);  
}  
};  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = loadXML;  
xmlData.load(“content.xml”);  
stop();

:glasses:

Thanks in Advance  
Vaishakh
