Código :
//--------------------------------------------------------------------------
// initial variables that might be useful to change
//--------------------------------------------------------------------------
// toggle for which file to play if none was set in html
// you can change the 'test.flv' in your filename
!_root.file ? file = "cap1.flv" : file = _root.file;
// toggle for autostarting the video
// you can change the 'true' in 'false'
!_root.autoStart ? autoStart = true: autoStart = _root.autoStart;
// toggle for the width and height of the video
// you can change them to the width and height you want
w = Stage.width;
h = Stage.height;
//--------------------------------------------------------------------------
// stream setup and functions
//--------------------------------------------------------------------------
// create and set netstream
nc = new NetConnection();
nc.connect(null);
ns = new NetStream(nc);
ns.setBufferTime(5);
// create and set sound object
this.createEmptyMovieClip("snd", 0);
snd.attachAudio(ns);
audio = new Sound(snd);
unmuteBut._visible = false;
//attach videodisplay
videoDisplay.attachVideo(ns);
// Retrieve duration meta data from netstream
ns.onMetaData = function(obj) {
this.totalTime = obj.duration;
// these two lines were used for automatically sizing
// it is now done by sizing the video to stage dimensions
// w = videoDisplay.width;
// h = videoDisplay.height;
};
// retrieve status messages from netstream
ns.onStatus = function(object) {
if (object.code == "NetStream.Play.Start") {
// this is invoked when the stream starts playing
// w = videoDisplay.width;
// h = videoDisplay.height;
} else if(object.code == "NetStream.Buffer.Full") {
// this is invoked when the stream is buffered
// w = videoDisplay.width;
// h = videoDisplay.height;
} else if(object.code == "NetStream.Play.Stop") {
// rewind and pause on when movie is finished
ns.seek(0);
ns.pause();
playBut._visible = true;
pauseBut._visible = false;
videoDisplay._visible = false;
playText.txt.text = "click to play";
}
};
//--------------------------------------------------------------------------
// controlbar functionality
//--------------------------------------------------------------------------
// play the movie and hide playbutton
function playMovie() {
if(!isStarted) {
ns.play(file);
playText.txt.text = "loading ..";
isStarted = true;
} else {
ns.pause();
}
pauseBut._visible = true;
playBut._visible = false;
videoDisplay._visible = true;
}
// pause the movie and hide pausebutton
function pauseMovie() {
ns.pause();
playBut._visible = true;
pauseBut._visible = false;
};
// video click action
videoBg.onPress = function() {
if(pauseBut._visible == false) {
playMovie();
} else {
pauseMovie();
}
};
// pause button action
pauseBut.onPress = function() {
pauseMovie();
};
// play button action
playBut.onPress = function() {
playMovie();
};
// file load progress
percentBar.onEnterFrame = function() {
loaded = this._parent.ns.bytesLoaded;
total = this._parent.ns.bytesTotal;
if (loaded == total && loaded>1000) {
percentBar._width = bw;
delete this.onEnterFrame;
} else {
percentBar._width = int(bw*loaded/total);
}
};
// play progress function
progressBar.onEnterFrame = function() {
this._width = bw*ns.time/ns.totalTime;
};
// start playhead scrubbing
centerBg.onPress = function() {
this.onEnterFrame = function() {
scl = this._xmouse*this._xscale/bw/100;
ns.seek(scl*ns.totalTime);
};
};
// stop playhead scrubbing
centerBg.onRelease = centerBg.onReleaseOutside = function () {
delete this.onEnterFrame;
pauseBut._visible == false ? videoDisplay.pause() : null;
};
// mute button action
muteBut.onPress = function() {
audio.setVolume(0);
unmuteBut._visible = true;
this._visible = false;
};
// unmute button action
unmuteBut.onPress = function() {
audio.setVolume(100);
muteBut._visible = true;
this._visible = false;
};
//--------------------------------------------------------------------------
// resize and position all items
//--------------------------------------------------------------------------
// set videodisplay dimensions
videoDisplay._width = videoBg._width = w;
videoDisplay._height = videoBg._height = h-20;
playText._x = w/2;
playText._y = h/2-10;
// resize the items on the left ..
leftBg._x = 0;
leftBg._y = h-20;
playBut._x = pauseBut._x = 12;
playBut._y = pauseBut._y = h-10;
// resize the items in the middle ..
centerBg._x = percentBar._x = progressBar._x = backBar._x = 21;
centerBg._y = h - 20;
percentBar._y = progressBar._y = h - 12;
bw = centerBg._width = percentBar._width = progressBar._width = w - 42;
// and resize the ones on the right ..
rightBg._x = w - 21;
rightBg._y = h - 20;
muteBut._x = unmuteBut._x = w - 11;
muteBut._y = unmuteBut._y = h - 10;
//--------------------------------------------------------------------------
// all done ? start the movie !
//--------------------------------------------------------------------------
// start playing the movie
// if no autoStart it searches for a placeholder jpg
// and hides the pauseBut
if (autoStart == true) {
playMovie();
} else {
pauseBut._visible = false;
imageStr = substring(file,0,file.length-3)+"jpg";
imageClip.loadMovie(imageStr);
} 