Section 1
//MainTimeline (videoplayer_fla.MainTimeline)
package videoplayer_fla {
import flash.events.*;
import flash.display.*;
import flash.media.*;
import flash.net.*;
import flash.utils.*;
import adobe.utils.*;
import flash.accessibility.*;
import flash.errors.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.printing.*;
import flash.profiler.*;
import flash.sampler.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.xml.*;
public dynamic class MainTimeline extends MovieClip {
public const BUFFER_TIME:Number = 8;
public const DEFAULT_VOLUME:Number = 0.6;
public const DISPLAY_TIMER_UPDATE_DELAY:int = 10;
public const SMOOTHING:Boolean = true;
public var mcVideoControls:MovieClip;
public var vidDisplay:Video;
public var bolLoaded:Boolean;
public var bolVolumeScrub:Boolean;
public var bolProgressScrub:Boolean;
public var intLastVolume:Number;
public var ncConnection:NetConnection;
public var nsStream:NetStream;
public var objInfo:Object;
public var strSource:String;
public var tmrDisplay:Timer;
public function MainTimeline(){
addFrameScript(0, frame1);
}
public function initVideoPlayer():void{
mcVideoControls.btnUnmute.visible = false;
mcVideoControls.btnPause.visible = false;
mcVideoControls.mcProgressFill.mcFillRed.width = 1;
mcVideoControls.mcProgressFill.mcFillGrey.width = 1;
stage.addEventListener(MouseEvent.MOUSE_UP, mouseReleased);
mcVideoControls.btnPause.addEventListener(MouseEvent.CLICK, pauseClicked);
mcVideoControls.btnPlay.addEventListener(MouseEvent.CLICK, playClicked);
mcVideoControls.btnStop.addEventListener(MouseEvent.CLICK, stopClicked);
mcVideoControls.btnMute.addEventListener(MouseEvent.CLICK, muteClicked);
mcVideoControls.btnUnmute.addEventListener(MouseEvent.CLICK, unmuteClicked);
mcVideoControls.mcVolumeScrubber.btnVolumeScrubber.addEventListener(MouseEvent.MOUSE_DOWN, volumeScrubberClicked);
mcVideoControls.mcProgressScrubber.btnProgressScrubber.addEventListener(MouseEvent.MOUSE_DOWN, progressScrubberClicked);
tmrDisplay = new Timer(DISPLAY_TIMER_UPDATE_DELAY);
tmrDisplay.addEventListener(TimerEvent.TIMER, updateDisplay);
ncConnection = new NetConnection();
ncConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
ncConnection.connect(null);
nsStream = new NetStream(ncConnection);
nsStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nsStream.client = this;
nsStream.bufferTime = BUFFER_TIME;
vidDisplay.attachNetStream(nsStream);
vidDisplay.smoothing = SMOOTHING;
mcVideoControls.mcVolumeScrubber.x = ((52 * DEFAULT_VOLUME) + 341);
mcVideoControls.mcVolumeFill.mcFillRed.width = ((mcVideoControls.mcVolumeScrubber.x - 394) + 52);
setVolume(DEFAULT_VOLUME);
}
public function playClicked(_arg1:MouseEvent):void{
if (!bolLoaded){
nsStream.play(strSource);
bolLoaded = true;
} else {
nsStream.resume();
};
vidDisplay.visible = true;
mcVideoControls.btnPause.visible = true;
mcVideoControls.btnPlay.visible = false;
}
public function pauseClicked(_arg1:MouseEvent):void{
nsStream.pause();
mcVideoControls.btnPause.visible = false;
mcVideoControls.btnPlay.visible = true;
}
public function stopClicked(_arg1:MouseEvent):void{
stopVideoPlayer();
}
public function muteClicked(_arg1:MouseEvent):void{
setVolume(0);
mcVideoControls.mcVolumeScrubber.x = 341;
mcVideoControls.mcVolumeFill.mcFillRed.width = 1;
}
public function unmuteClicked(_arg1:MouseEvent):void{
setVolume(intLastVolume);
mcVideoControls.mcVolumeScrubber.x = ((53 * intLastVolume) + 341);
mcVideoControls.mcVolumeFill.mcFillRed.width = ((mcVideoControls.mcVolumeScrubber.x - 394) + 53);
}
public function volumeScrubberClicked(_arg1:MouseEvent):void{
bolVolumeScrub = true;
mcVideoControls.mcVolumeScrubber.startDrag(false, new Rectangle(341, 19, 53, 0));
}
public function progressScrubberClicked(_arg1:MouseEvent):void{
bolProgressScrub = true;
mcVideoControls.mcProgressScrubber.startDrag(false, new Rectangle(0, 2, 432, 0));
}
public function mouseReleased(_arg1:MouseEvent):void{
bolVolumeScrub = false;
bolProgressScrub = false;
mcVideoControls.mcProgressScrubber.stopDrag();
mcVideoControls.mcVolumeScrubber.stopDrag();
mcVideoControls.mcProgressFill.mcFillRed.width = (mcVideoControls.mcProgressScrubber.x + 5);
mcVideoControls.mcVolumeFill.mcFillRed.width = ((mcVideoControls.mcVolumeScrubber.x - 394) + 53);
if (((mcVideoControls.mcVolumeScrubber.x - 341) / 53) > 0){
intLastVolume = ((mcVideoControls.mcVolumeScrubber.x - 341) / 53);
};
}
public function updateDisplay(_arg1:TimerEvent):void{
if (bolProgressScrub){
nsStream.seek(Math.round(((mcVideoControls.mcProgressScrubber.x * objInfo.duration) / 432)));
} else {
mcVideoControls.mcProgressScrubber.x = ((nsStream.time * 432) / objInfo.duration);
};
mcVideoControls.lblTimeDuration.htmlText = ((("<font color='#ffffff'>" + formatTime(nsStream.time)) + "</font> / ") + formatTime(objInfo.duration));
mcVideoControls.mcProgressFill.mcFillRed.width = (mcVideoControls.mcProgressScrubber.x + 5);
mcVideoControls.mcProgressFill.mcFillGrey.width = ((nsStream.bytesLoaded * 438) / nsStream.bytesTotal);
if (bolVolumeScrub){
setVolume(((mcVideoControls.mcVolumeScrubber.x - 341) / 53));
mcVideoControls.mcVolumeFill.mcFillRed.width = ((mcVideoControls.mcVolumeScrubber.x - 394) + 53);
};
}
public function onMetaData(_arg1:Object):void{
objInfo = _arg1;
tmrDisplay.start();
}
public function netStatusHandler(_arg1:NetStatusEvent):void{
switch (_arg1.info.code){
case "NetStream.Play.StreamNotFound":
trace(("Stream not found: " + strSource));
break;
case "NetStream.Play.Stop":
stopVideoPlayer();
break;
};
}
public function stopVideoPlayer():void{
nsStream.pause();
nsStream.seek(0);
vidDisplay.visible = false;
mcVideoControls.btnPause.visible = false;
mcVideoControls.btnPlay.visible = true;
}
public function setVolume(_arg1:Number=0):void{
var _local2:* = new SoundTransform(_arg1);
nsStream.soundTransform = _local2;
if (_arg1 > 0){
mcVideoControls.btnMute.visible = true;
mcVideoControls.btnUnmute.visible = false;
} else {
mcVideoControls.btnMute.visible = false;
mcVideoControls.btnUnmute.visible = true;
};
}
public function formatTime(_arg1:int):String{
var _local2:int = Math.round(_arg1);
var _local3:int;
if (_local2 > 0){
while (_local2 > 59) {
_local3++;
_local2 = (_local2 - 60);
};
return (String(((((((_local3 < 10)) ? "0" : "" + _local3) + ":") + ((_local2 < 10)) ? "0" : "") + _local2)));
} else {
};
return (!NULL!);
}
function frame1(){
bolLoaded = false;
bolVolumeScrub = false;
bolProgressScrub = false;
intLastVolume = DEFAULT_VOLUME;
strSource = "http://www.mtpixel.com/demo.mp4";
initVideoPlayer();
}
}
}//package videoplayer_fla