【自制】Flash视频播放器 o(∩_∩)o 完成度不错的话就做成插件吧

自己是一个很喜欢看动漫听音乐的人。所以呢,经常会在博客上插入视频的说。

但是呢~外链的youku,tudou,56的自带播放器很难看,而且很多功能都没有,比如评论功能啊,循环播放功能啊。这一点嘛,bilibili就做的不错。但是bilibili那个miniplayer似乎死掉了,现在这个播放器还关不掉自动播放。

而且呢wordpress的视频插件flash video player似乎还要收费的,否则会有水印啊,不给力啊,不给力。

干脆就自己做一个好了!

研究了1个小时,目前工作成果是 自制按钮播放,自制按钮全屏,自制文本框显示当前时间/总时间,循环播放视频。嗯嗯,晚些时候再把滚动条研究一下吧。我的设想是滚动条上的滑块按 当前时间/总时间 的百分比来移动的说。

下面是Demo

左下角第一个按钮点击后播放.底部按钮分别为 播放/暂停 | 停止 | 循环 | 全屏(实验作品,懒得做那么多精细,各种偷懒啊 😀 )

载入视频是通过外部传递参数的形式

视频的源文件为:澄空Sumisora【初音ミク】【3DPV】

[fvp info=澄空Sumisora【初音ミク】【3DPV】]http://www.hcgcn.com/xsk/Sumisora.flv[/fvp]

以下是程序源码:

package player_fla
{
import fl.video.*;
import flash.display.*;
import flash.events.*;
import flash.geom.*;

dynamic public class MainTimeline extends MovieClip
{
public var myLogo:MovieClip;
public var myDisplay:FLVPlayback;
public var myBar:MovieClip;
public var onLoop:Boolean;
public var onScreen:Boolean;
public var onSound:Boolean;
public var toHours:uint;
public var toMinutes:uint;
public var toSeconds:uint;
public var nowHours:uint;
public var nowMinutes:uint;
public var nowSeconds:uint;

public function MainTimeline()
{
addFrameScript(0, this.frame1);
this.__setProp_myDisplay_();
return;
}// end function

public function downScreen(param1:MouseEvent)
{
this.onScreen = !this.onScreen;
if (this.onScreen)
{
stage.displayState = "fullScreen";
}
else
{
stage.displayState = "normal";
}
return;
}// end function

public function downPlay(param1:MouseEvent)
{
if (this.myDisplay.playing)
{
this.myBar.myPlay.gotoAndStop(2);
this.myDisplay.pause();
this.myLogo.alpha = 1;
this.myBar.alpha = 1;
}
else
{
this.myBar.myPlay.gotoAndStop(1);
this.myDisplay.play();
this.myLogo.alpha = 0;
this.myBar.alpha = 0;
}
return;
}// end function

public function downLoop(param1:MouseEvent)
{
this.onLoop = !this.onLoop;
if (this.onLoop)
{
stage.addEventListener(Event.ENTER_FRAME, this.roundLoop);
}
else
{
stage.removeEventListener(Event.ENTER_FRAME, this.roundLoop);
}
return;
}// end function

public function roundLoop(param1:Event)
{
this.myBar.myLoop.rotation = this.myBar.myLoop.rotation + 10;
return;
}// end function

public function downVolume(param1:MouseEvent)
{
this.onSound = !this.onSound;
if (!this.onSound)
{
this.myBar.myVolume.gotoAndStop(2);
this.myDisplay.volume = 0;
this.myBar.myVolumeBar.x = this.myBar.myVolumeLine.x;
}
else
{
this.myBar.myVolume.gotoAndStop(1);
this.myDisplay.volume = 1;
this.myBar.myVolumeBar.x = this.myBar.myVolumeLine.x + this.myBar.myVolumeLine.width;
}
return;
}// end function

public function downVolumeBar(param1:Event)
{
stage.addEventListener(MouseEvent.MOUSE_MOVE, this.moveVolumeBar);
return;
}// end function

public function moveVolumeBar(param1:Event)
{
this.myBar.myVolumeBar.startDrag(true, new Rectangle(this.myBar.myVolumeLine.x, this.myBar.myVolumeLine.y - 3, this.myBar.myVolumeLine.width, 0));
stage.addEventListener(MouseEvent.MOUSE_UP, this.upVolumeBar);
return;
}// end function

public function upVolumeBar(param1:MouseEvent)
{
var _loc_2:* = Math.abs((this.myBar.myVolumeLine.x - this.myBar.myVolumeBar.x) / this.myBar.myVolumeLine.width);
this.myDisplay.volume = _loc_2;
stage.removeEventListener(MouseEvent.MOUSE_MOVE, this.moveVolumeBar);
stage.removeEventListener(MouseEvent.MOUSE_UP, this.upVolumeBar);
this.myBar.myVolumeBar.stopDrag();
return;
}// end function

public function bufferBarCon(param1:Event)
{
var _loc_2:* = this.myDisplay.playheadTime / this.myDisplay.totalTime * 100;
this.myBar.myBufferBar.x = this.myBar.myBuffer.x + this.myBar.myBuffer.width / 100 * _loc_2;
return;
}// end function

public function downBufferBar(param1:MouseEvent)
{
this.myBar.myBufferBar.removeEventListener(Event.ENTER_FRAME, this.bufferBarCon);
stage.addEventListener(MouseEvent.MOUSE_MOVE, this.moveBufferBar);
return;
}// end function

public function moveBufferBar(param1:MouseEvent)
{
this.myBar.myBufferBar.startDrag(true, new Rectangle(this.myBar.myBuffer.x, this.myBar.myBuffer.y - 3.5, this.myBar.myBuffer.width, 0));
stage.addEventListener(MouseEvent.MOUSE_UP, this.upBufferBar);
return;
}// end function

public function upBufferBar(param1:MouseEvent)
{
var _loc_2:* = Math.abs((this.myBar.myBuffer.x - this.myBar.myBufferBar.x) / this.myBar.myBuffer.width);
this.myDisplay.playheadTime = _loc_2 * this.myDisplay.totalTime;
stage.removeEventListener(MouseEvent.MOUSE_MOVE, this.moveBufferBar);
stage.removeEventListener(MouseEvent.MOUSE_UP, this.upBufferBar);
this.myBar.myBufferBar.stopDrag();
this.myBar.myBufferBar.addEventListener(Event.ENTER_FRAME, this.bufferBarCon);
return;
}// end function

public function bufferBar(param1)
{
var _loc_2:* = param1.bytesLoaded / param1.bytesTotal * 100;
this.myBar.myBuffer.gotoAndStop(_loc_2);
return;
}// end function

public function Con(param1:Event)
{
var _loc_2:String;
var _loc_3:String;
this.toHours = this.myDisplay.totalTime / 3600;
this.toMinutes = this.myDisplay.totalTime / 60;
this.toSeconds = this.myDisplay.totalTime % 60;
this.nowHours = this.myDisplay.totalTime / 3600;
this.nowMinutes = this.myDisplay.playheadTime / 60;
this.nowSeconds = this.myDisplay.playheadTime % 60;
_loc_3 = this.toHours + ":" + this.toMinutes + ":" + this.toSeconds;
_loc_2 = this.nowHours + ":" + this.nowMinutes + ":" + this.nowSeconds;
this.myBar.myTime.text = _loc_2 + "/" + _loc_3;
if (_loc_2 == _loc_3)
{
if (this.onLoop)
{
this.myDisplay.playheadTime = 0;
this.myDisplay.play();
}
else
{
this.myLogo.alpha = 1;
this.myDisplay.playheadTime = 0;
this.myDisplay.stop();
this.myBar.myPlay.gotoAndStop(1);
}
}
if (mouseY > stage.stageHeight / 2)
{
this.myBar.alpha = 1;
}
else
{
this.myBar.alpha = 0;
}
this.myLogo.myBufferImg.rotation = this.myLogo.myBufferImg.rotation + 10;
return;
}// end function

function __setProp_myDisplay_()
{
try
{
this.myDisplay["componentInspectorSetting"] = true;
}
catch (e:Error)
{
}
this.myDisplay.align = "center";
this.myDisplay.autoPlay = true;
this.myDisplay.dvrFixedDuration = false;
this.myDisplay.dvrIncrement = 1800;
this.myDisplay.dvrIncrementVariance = 300;
this.myDisplay.dvrSnapToLive = true;
this.myDisplay.isDVR = false;
this.myDisplay.isLive = false;
this.myDisplay.scaleMode = "exactFit";
this.myDisplay.skin = "";
this.myDisplay.skinAutoHide = false;
this.myDisplay.skinBackgroundAlpha = 1;
this.myDisplay.skinBackgroundColor = 6710886;
this.myDisplay.source = "";
this.myDisplay.volume = 1;
try
{
this.myDisplay["componentInspectorSetting"] = false;
}
catch (e:Error)
{
}
return;
}// end function

function frame1()
{
stage.showDefaultContextMenu = false;
this.onLoop = false;
this.onScreen = false;
this.onSound = true;
this.myBar.myBufferBar.buttonMode = true;
this.myBar.myVolumeBar.buttonMode = true;
this.myBar.myVolume.buttonMode = true;
this.myBar.myLoop.buttonMode = true;
this.myDisplay.source = this.loaderInfo.parameters["myUrl"];
this.myDisplay.autoPlay = this.loaderInfo.parameters["isPlay"];
this.myDisplay.fullScreenTakeOver = false;
this.myDisplay.addEventListener(ProgressEvent.PROGRESS, this.bufferBar);
this.myBar.myBufferBar.addEventListener(MouseEvent.MOUSE_DOWN, this.downBufferBar);
this.myBar.myBufferBar.addEventListener(Event.ENTER_FRAME, this.bufferBarCon);
this.myBar.myVolumeBar.addEventListener(MouseEvent.MOUSE_DOWN, this.downVolumeBar);
this.myBar.myVolume.addEventListener(MouseEvent.CLICK, this.downVolume);
this.myBar.myLoop.addEventListener(MouseEvent.CLICK, this.downLoop);
this.myBar.myPlay.addEventListener(MouseEvent.CLICK, this.downPlay);
this.myBar.myScreen.addEventListener(MouseEvent.CLICK, this.downScreen);
this.myLogo.addEventListener(MouseEvent.CLICK, this.downPlay);
stage.addEventListener(Event.ENTER_FRAME, this.Con);
return;
}// end function

 }
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This site uses Akismet to reduce spam. Learn how your comment data is processed.