the rest:
// play video (no fast play)
function doPlay()
{
currFastDir = 0;
currFastIndex = 0;
trace(“doPlay”);
var timecode:Number = nsPlay.time;
_root.isProgressUpdate = false;
if (!_root.isPlaying)
nsPlay.pause(false);
nsPlay.seek(timecode);
_root.isPlaying = true;
}
// event for clicking the play button
// if we are paused or in fast play mode just play the video
// else pause the video
function doPlayToggle()
{
if (!isPlaying)
doPlay();
else
{
_root.isProgressUpdate = false;
_root.isPlaying = false;
nsPlay.pause(true);
}
}
// rewind to the beginning of the movie and start playing
function doRewind()
{
_root.isProgressUpdate = false;
nsPlay.seek(0);
}
// update the progress bar
function setProgress(timecode:Number)
{
var totalWidth:Number = slider.sliderBack._width;
var newTimecode:Number = timecode;
var newWidth = (totalWidth*newTimecode)/duration;
if (newWidth > totalWidth)
newWidth = totalWidth;
if (!_root.isScrubbing && _root.isProgressUpdate)
slider.sliderSlide._width = newWidth;
}
function updateProgress()
{
setProgress(nsPlay.time);
}
// calculate the movie scrub location based on current mouse position
function calcScrub()
{
var xpos:Number = _root.slider._xmouse;
var xmax:Number = _root.slider._width;
if (xpos < 0)
xpos = 0;
else if (xpos > xmax)
xpos = xmax;
scrubTime = (duration*xpos)/xmax;
slider.sliderSlide._width = xpos;
}
// update the scrub location as we are scrubbing
function updateScrub()
{
calcScrub();
}
// start scrubbing
function startScrub()
{
scrubTimer = setInterval(_root, “updateScrub”, 250);
isScrubbing = true;
scrubTime = -1;
calcScrub();
scrubIsPlaying = _root.isPlaying;
if (_root.isPlaying)
nsPlay.pause(true);
}
// stop scrubbing and setup new play position
function stopScrub()
{
if (scrubTimer)
clearInterval(scrubTimer);
scrubTimer = 0;
if (scrubTime != -1)
{
_root.isProgressUpdate = false;
if (scrubIsPlaying)
{
_root.isPlaying = true;
nsPlay.pause(false);
nsPlay.seek(scrubTime);
}
else
{
_root.isPlaying = false;
nsPlay.seek(scrubTime);
}
}
isScrubbing = false;
}
function updateVideoSize()
{
// when we finally get a valid video width/height resize the video frame to make it proportional
if (videoObj.width != videoLastW || videoObj.height != videoLastH)
{
videoLastW = videoObj.width;
videoLastH = videoObj.height;
var videoAspectRatio:Number = videoLastW/videoLastH;
var frameAspectRatio:Number = saveVideoObjW/saveVideoObjH;
adjVideoObjW = saveVideoObjW;
adjVideoObjH = saveVideoObjH;
if (videoAspectRatio > frameAspectRatio)
adjVideoObjH = saveVideoObjW/videoAspectRatio;
else
adjVideoObjW = saveVideoObjH*videoAspectRatio;
videoObj._width = adjVideoObjW;
videoObj._height = adjVideoObjH;
videoObj._y = saveVideoObjY + saveVideoObjH - adjVideoObjH;
videoObj._x = (Stage.width - adjVideoObjW)/2;
videoObj._visible = true;
}
}
// show/hide the controls when we enter/leave fullscreen
function hideAllControls(doHide:Boolean)
{
_root.fpsText._visible = !doHide;
_root.bufferLenText._visible = !doHide;
_root.logo._visible = !doHide;
_root.connect._visible = !doHide;
_root.controls._visible = !doHide;
_root.doFullscreen._visible = !doHide;
_root.slider._visible = !doHide;
_root.backdrop._visible = !doHide;
_root.playerVersion._visible = !doHide;
}
function enterLeaveFullscreen(isFullscreen:Boolean)
{
trace("enterLeaveFullscreen: "+enterLeaveFullscreen);
hideAllControls(isFullscreen);
if (!isFullscreen)
{
// reset back to original state
Stage.scaleMode = “noScale”;
videoObj._width = adjVideoObjW;
videoObj._height = adjVideoObjH;
videoObj._y = saveVideoObjY + saveVideoObjH - adjVideoObjH;
videoObj._x = (Stage.width - adjVideoObjW)/2;
}
}
function enterFullscreen()
{
if (hardwareScaleCapable)
{
// best settings for hardware scaling
videoObj.smoothing = false;
videoObj.deblocking = 0;
// set the video frame size to the actual video size
videoObj._width = videoObj.width;
videoObj._height = videoObj.height;
// grab the portion of the stage that is just the video frame
Stage[“fullScreenSourceRect”] = new Rectangle(
videoObj._x, videoObj._y,
videoObj.width, videoObj.height);
}
else
{
Stage.scaleMode = “noBorder”;
var videoAspectRatio:Number = videoObj.width/videoObj.height;
var stageAspectRatio:Number = Stage.width/Stage.height;
var screenAspectRatio:Number = System.capabilities.screenResolutionX/System.capabilities.screenResolutionY;
// calculate the width and height of the scaled stage
var stageObjW:Number = Stage.width;
var stageObjH:Number = Stage.height;
if (stageAspectRatio > screenAspectRatio)
stageObjW = Stage.height*screenAspectRatio;
else
stageObjH = Stage.width/screenAspectRatio;
// calculate the width and height of the video frame scaled against the new stage size
var fsVideoObjW:Number = stageObjW;
var fsVideoObjH:Number = stageObjH;
if (videoAspectRatio > screenAspectRatio)
fsVideoObjH = stageObjW/videoAspectRatio;
else
fsVideoObjW = stageObjH*videoAspectRatio;
// scale the video object
videoObj._width = fsVideoObjW;
videoObj._height = fsVideoObjH;
videoObj._x = (stageObjW-fsVideoObjW)/2.0;
videoObj._y = (stageObjH-fsVideoObjH)/2.0;
}
Stage[“displayState”] = “fullScreen”;
}
function testVersion(v0:Number, v1:Number, v2:Number, v3:Number):Boolean
{
var version:String = System.capabilities.version;
var index:Number = version.indexOf(" ");
version = version.substr(index+1);
var verParts:Array = version.split(",");
var i:Number;
var ret:Boolean = true;
while(true)
{
if (Number(verParts[0]) < v0)
{
ret = false;
break;
}
else if (Number(verParts[0]) > v0)
break;
if (Number(verParts[1]) < v1)
{
ret = false;
break;
}
else if (Number(verParts[1]) > v1)
break;
if (Number(verParts[2]) < v2)
{
ret = false;
break;
}
else if (Number(verParts[2]) > v2)
break;
if (Number(verParts[3]) < v3)
{
ret = false;
break;
}
break;
}
trace(“testVersion: “+System.capabilities.version+”>=”+v0+","+v1+","+v2+","+v3+": "+ret);
return ret;
}
var h264Capable:Boolean = testVersion(9, 0, 115, 0);
playerVersion.text = (h264Capable?“H.264 Ready (”:“No H.264 (”)+System.capabilities.version+")";
if (!h264Capable)
playerVersion.textColor = 0xee0000;
Stage.align = “TL”;
Stage.scaleMode = “noScale”;
nc.onBWDone = function(kbitDown, deltaDown, deltaTime, latency) {
trace(“onBWDone: kbitDown:”+kbitDown+" deltaDown:"+deltaDown+" deltaTime:"+deltaTime+" latency:"+latency);
// app logic based on the bandwidth detected follows here
detected_bw = kbitDown;
// close the Netconnection to bwcheck
this.close();
}
nc.onBWCheck = function() {
trace(“onBWCheck”);
return ++counter; // Serverside, just ignore any return value, For now return the call count
}
mainInit();
setProgress(0);