?? videoplayer.as
字號:
}
if (showShare) {
shareMC._x = Math.floor(mWidth / 2);
shareMC._y = Math.floor(mHeight / 2);
if (shareMC._visible) {
shareMC.shareBckMC._width = Stage.width;
shareMC.shareBckMC._height = Stage.height;
}
}
if (showMiddleBtn) {
middlePlayBtn._x = Math.floor((mWidth) / 2);
middlePlayBtn._y = Math.floor((mHeight - controlsMC._height) / 2);
}
}else {
preloaderMC._x = Math.floor((mWidth - preloaderMC._width) / 2);
preloaderMC._y = Math.floor((mHeight - preloaderMC._height) / 2);
}
}
/**
* This function calculate the max values of video that can have to fit in the available space
* and set it to the properly coordonates
*/
function setSizes(pMC:MovieClip, newWidth:Number, newHeight:Number):Void {
var currWidth:Number = pMC._width;
var currHeight:Number = pMC._height;
var proc1:Number = newWidth / flvWidth;
var proc2:Number = newHeight / flvHeight;
if (proc1 > proc2) {
pMC._height = newHeight;
pMC._xscale = pMC._yscale;
}else{
pMC._width = newWidth;
pMC._yscale = pMC._xscale;
}
pMC._x = Math.floor((newWidth - pMC._width)/2);
pMC._y = Math.floor((newHeight - pMC._height) / 2);
}
//---------------------------------------------------------------------------------<
//------------------------------ Generate Link ------------------------------------<
/**
* Get the link header for extracting the video_id and t parameters for YouTube videos
*/
private function getLink():Void {
youtubeData = this.createEmptyMovieClip ("youtubeData", getNextHighestDepth ());
if (flv.indexOf("watch") != - 1) {
flv = "http://www.youtube.com/watch?v=" + flv.split("youtube.com/watch?v=")[1];
}else {
flv = "http://www.youtube.com/watch?v=" + flv.split("youtube.com/v/")[1];
}
youtubeData.onData = Delegate.create(this, linkResult);
youtubeData.loadVariables(playerPath + "getLink.php?link=" + escape(flv), "GET");
}
/**
* Extracting video_id and t parameters from YouTube links and create the new path for the video that we need to play
* @param pLink
*/
private function linkResult():Void {
flv = "http://cache.googlevideo.com/get_video?video_id=" + youtubeData.video_id + "&t=" + youtubeData.t +"&origin=youtube.com";
loadVideo();
}
//---------------------------------------------------------------------------------<
private function loadVideo():Void {
connection_nc = new NetConnection();
connection_nc.connect(null);
stream_ns = new NetStream(connection_nc);
stream_ns.setBufferTime(5);
videoDisplay.attachVideo(stream_ns);
volumeMC.attachAudio(stream_ns);
flvSnd = new Sound(volumeMC);
stream_ns.onMetaData = Delegate.create(this, flvOnMetaData);
stream_ns.onStatus = Delegate.create(this, checkStatus);
stream_ns.play(flv);
volumeMC.volumeScrubBtn._x = volumeMC.maskBarMC._x = Math.floor((volume / 100 ) * (volumeMC.volumeWedgeMC._width - 8)) + volumeMC.volumeWedgeMC._x + 4;
flvSnd.setVolume(volume);
volumeMC.speakerBtn.gotoAndStop(Math.round(volume / 33) + 1);
bytesLoadedInterval = setInterval(this, "checkBytesLoaded", 10);
}
private function checkStatus(infoObject:Object) {
if (!metaDataLoaded && infoObject["code"] != "NetStream.Play.Start") {
flvOnMetaData();
}
}
private function checkBytesLoaded():Void {
var pctLoaded:Number = stream_ns.bytesLoaded / stream_ns.bytesTotal;
timelineMC.progressBarMC._width = Math.floor(pctLoaded * (timelineMC.timelineBck._width - 3));
if (pctLoaded >= 1) {
clearInterval(bytesLoadedInterval);
}
}
private function flvOnMetaData(infoObject:Object):Void {
if (!metaDataLoaded) {
clickableAreaMC._width = mWidth;
clickableAreaMC._height = mHeight - controlsBckMC._height;
if (keepAspectRatio){
if (infoObject["width"] != undefined) {
flvWidth = infoObject["width"];
flvHeight = infoObject["height"];
}
videoDisplay._width = flvWidth;
videoDisplay._height = flvHeight;
setSizes(displayMC, mWidth, mHeight - controlsBckMC._height);
}else {
videoDisplay._width = mWidth;
videoDisplay._height = mHeight - controlsBckMC._height;
displayMC._x = 0;
displayMC._y = 0;
}
if (showWatermark) {
watermarkMC._x = displayMC._x + displayMC._width - watermarkMC._width - 10;
watermarkMC._y = displayMC._y + displayMC._height - watermarkMC._height - 10;
watermarkMC._visible = true;
}
if (showShare) {
shareMC._x = Math.floor(mWidth / 2);
shareMC._y = Math.floor(mHeight / 2);
}
if (showMiddleBtn) {
middlePlayBtn._x = Math.floor((mWidth) / 2);
middlePlayBtn._y = Math.floor((mHeight - controlsMC._height) / 2);
}
if (infoObject["duration"] != undefined) {
totalTime = Math.floor(infoObject["duration"]);
}
var seconds:String = String(Math.floor(totalTime)%60);
var minutes:String = String(Math.floor(totalTime - Number(seconds)) / 60);
if (seconds.length == 1) {
seconds = "0" + seconds;
}
if (minutes.length == 1) {
minutes = "0" + minutes;
}
timesMC.totalTimeBox.text = minutes + ":" + seconds;
if (spaceKeyListener) {
var keyListener:Object = new Object();
keyListener.onKeyDown = Delegate.create(this, checkSpacePress);
Key.addListener(keyListener);
}
if (clickListener) {
clickableAreaMC.onPress = Delegate.create(this, displayPress);
clickableAreaMC.useHandCursor = false;
}
this.controlsMC._visible = true;
this.preloaderMC._visible = false;
stream_ns.pause();
if (autoPlay) {
togglePlayPause();
videoDisplay._visible = true;
}else {
showMiddleBtn();
displayPreviewImage();
}
}else {
if (!loop) {
showMiddleBtn();
displayPreviewImage();
if (playPauseMC.pauseBtn._visible) {
togglePlayPause();
}
}
}
metaDataLoaded = true;
}
private function stopRelease():Void {
stream_ns.seek(0);
stream_ns.pause(true);
playPauseMC.pauseBtn._visible = false;
playPauseMC.playBtn._visible = true;
showMiddleBtn();
displayPreviewImage();
clearInterval(scrubPosInterval);
timesMC.elapsedTimeBox.text = "00:00";
timelineMC.scrubBtn._x = 4;
}
public function togglePlayPause():Void {
stream_ns.pause();
playPauseMC.pauseBtn._visible = !playPauseMC.pauseBtn._visible;
playPauseMC.playBtn._visible = !playPauseMC.playBtn._visible;
if (playPauseMC.pauseBtn._visible) {
hidePreviewImage();
hideMiddleBtn();
var proc:Number = (timelineMC.scrubBtn._x - 4)/ (timelineMC.timelineBck._width - 7);
if (proc == 1) {
stream_ns.seek(0);
}
clearInterval(scrubPosInterval);
scrubPosInterval = setInterval(this, "scrubPos", 10);
}else {
showMiddleBtn();
clearInterval(scrubPosInterval);
}
}
//---------------------------- Volume Functions -----------------------------------<
private function dragVol():Void {
volumeInterval = setInterval(this, "setVol", 10);
}
private function stopDragVol():Void {
clearInterval(volumeInterval);
}
private function setVol():Void {
if (volumeMC._xmouse < volumeMC.volumeWedgeMC._x + 4) {
volumeMC.volumeScrubBtn._x = volumeMC.maskBarMC._x = volumeMC.volumeWedgeMC._x + 4;
}else if (volumeMC._xmouse > volumeMC.volumeWedgeMC._x + volumeMC.volumeWedgeMC._width - 4) {
volumeMC.volumeScrubBtn._x = volumeMC.maskBarMC._x = volumeMC.volumeWedgeMC._x + volumeMC.volumeWedgeMC._width - 4;
}else {
volumeMC.volumeScrubBtn._x = volumeMC.maskBarMC._x = volumeMC._xmouse;
}
var pVolume = (volumeMC.volumeScrubBtn._x - volumeMC.volumeWedgeMC._x - 4)/ (volumeMC.volumeWedgeMC._width - 8) * 100;
flvSnd.setVolume(pVolume);
if (pVolume == 0){
volumeMC.speakerBtn.gotoAndStop(5);
}else {
volumeMC.speakerBtn.gotoAndStop(Math.round(pVolume / 33) + 1);
}
}
private function muteVol():Void {
if (volumeMC.speakerBtn._currentframe != 5) {
volumeMC.volumeScrubBtn._x = volumeMC.maskBarMC._x = volumeMC.volumeWedgeMC._x + 4;
volume = flvSnd.getVolume();
flvSnd.setVolume(0);
volumeMC.speakerBtn.gotoAndStop(5);
}else {
volumeMC.volumeScrubBtn._x = volumeMC.maskBarMC._x = Math.floor((volume / 100 ) * (volumeMC.volumeWedgeMC._width - 8)) + volumeMC.volumeWedgeMC._x + 4;
flvSnd.setVolume(volume);
volumeMC.speakerBtn.gotoAndStop(Math.round(volume / 33) + 1);
}
}
//---------------------------------------------------------------------------------<
//---------------------------- Scrub Functions ------------------------------------<
private function dragScrub():Void {
hidePreviewImage();
timelineMC.scrubBtn._x = timelineMC._xmouse;
if (playPauseMC.pauseBtn._visible) {
togglePlayPause();
wasPlaying = true;
}else {
wasPlaying = false;
}
timelineMC.scrubBtn.startDrag(false, 4, timelineMC.scrubBtn._y, timelineMC.progressBarMC._width, timelineMC.scrubBtn._y);
clearInterval(bytesLoadedInterval);
clearInterval(progressPosInterval);
progressPosInterval = setInterval(this, "progressPos", 10);
}
private function progressPos():Void {
timelineMC.scrubBarMC._width = timelineMC.scrubBtn._x;
var proc:Number = (timelineMC.scrubBtn._x - 4) / (timelineMC.timelineBck._width - 7);
stream_ns.seek(Math.floor(totalTime * proc));
stream_ns.pause(true);
setElapsedTime();
}
private function stopDragScrub():Void {
timelineMC.scrubBtn.stopDrag();
clearInterval(progressPosInterval);
if (wasPlaying) {
togglePlayPause();
}
if (timelineMC.progressBarMC._width < timelineMC.timelineBck._width - 3) {
bytesLoadedInterval = setInterval(this, "checkBytesLoaded", 10);
}
}
private function scrubPos():Void {
var proc:Number = stream_ns.time / totalTime;
timelineMC.scrubBtn._x = timelineMC.scrubBarMC._width = Math.floor((timelineMC.timelineBck._width - 7) * proc) + 4;
if (int(proc) == 1) {
stream_ns.seek(0);
if (!loop) {
togglePlayPause();
timesMC.elapsedTimeBox.text = "00:00";
timelineMC.scrubBtn._x = 4;
}
}else {
setElapsedTime();
}
}
//---------------------------------------------------------------------------------<
//----------------------------- Middle and Preview Image Functions ----------------<
private function displayPreviewImage():Void {
if (showPreviewImage && !shareMC._visible){
videoDisplay._visible = false;
tween3.stop();
tween3 = new Tween(this.previewImageMC, "_alpha", Regular.easeInOut, this.previewImageMC._alpha, 100, 0.4, true);
}else {
videoDisplay._visible = true;
}
}
private function hidePreviewImage():Void {
if (showPreviewImage && !shareMC._visible){
videoDisplay._visible = true;
tween3.stop();
tween3 = new Tween(this.previewImageMC, "_alpha", Regular.easeInOut, this.previewImageMC._alpha, 0, 0.4, true);
}
}
private function showMiddleBtn():Void {
if (showMiddlePlayButton && !shareMC._visible){
tween1.stop();
tween1 = new Tween(this.middlePlayBtn, "_width", Elastic.easeInOut, this.middlePlayBtn._width, 80, 1, true);
tween2.stop();
tween2 = new Tween(this.middlePlayBtn, "_height", Elastic.easeInOut, this.middlePlayBtn._height, 80, 1, true);
}
}
private function hideMiddleBtn():Void {
if (showMiddlePlayButton && !shareMC._visible){
tween1.stop();
tween1 = new Tween(this.middlePlayBtn, "_width", Elastic.easeInOut, this.middlePlayBtn._width, 0, 1, true);
tween2.stop();
tween2 = new Tween(this.middlePlayBtn, "_height", Elastic.easeInOut, this.middlePlayBtn._height, 0, 1, true);
}
}
//---------------------------------------------------------------------------------<
private function setElapsedTime():Void {
var proc:Number = stream_ns.time / totalTime;
var seconds:String = String(Math.floor(totalTime * proc)%60);
var minutes:String = String(Math.floor(totalTime * proc - Number(seconds)) / 60);
if (seconds.length == 1) {
seconds = "0" + seconds;
}
if (minutes.length == 1) {
minutes = "0" + minutes;
}
if (!isNaN(seconds) && !isNaN(minutes)){
timesMC.elapsedTimeBox.text = minutes + ":" + seconds;
}
}
private function checkSpacePress():Void {
if (Key.isDown(Key.SPACE)) {
togglePlayPause();
}
}
private function displayPress():Void {
togglePlayPause();
}
private function openShare():Void {
shareDisplayMC.show();
}
public function get getPlayerPath():String {
return playerPath;
}
public function get getPlayerPage():String {
return playerPage;
}
public function get getStafImage():String {
return stafImage;
}
public function get getPauseBtn():MovieClip {
return playPauseMC.pauseBtn;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -