📄 vcastr3.as
字号:
package com.ruochi.video{
import com.ruochi.utils.about;
import com.ruochi.video.CenterBtn;
import com.ruochi.video.DefaultControlPanel;
import com.ruochi.utils.defaultBoolean;
import com.ruochi.utils.defaultNum;
import com.ruochi.utils.defaultString
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import com.ruochi.net.CrossURLLoader;
import com.ruochi.utils.deleteArrayElement;
import com.ruochi.component.SimpleAlert;
import com.ruochi.video.VcastrConfig;
import com.ruochi.utils.paramToVar;
import com.ruochi.video.VideoPlayer;
import com.ruochi.video.VideoEvent;
import com.ruochi.utils.xmlToVar;
public class Vcastr3 extends Sprite {
private var _videoPlayer:VideoPlayer = new VideoPlayer();
private var _unLoadPlugInNameArray:Array = new Array();
private var _videoXml:XML;
private var _activeVideoId:int = 0;
private var _defaultControlPanel:DefaultControlPanel;
private var _centerBtn:CenterBtn = new CenterBtn();
public function Vcastr3() {
init();
}
private function init():void {
initVar();
addChild(_videoPlayer);
for (var i:int = 0; i < _unLoadPlugInNameArray.length; i++) {
var loader:Loader = new Loader();
loader.name = _unLoadPlugInNameArray[i];
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete, false, 0, true)
loader.load(new URLRequest(_unLoadPlugInNameArray[i]));
}
if (VcastrConfig.dataXml==null) {
var xmlLoader:CrossURLLoader = new CrossURLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onXmlLoaderComplete, false, 0, true);
xmlLoader.crossLoad(new URLRequest(VcastrConfig.xml));
}else {
checkInit();
}
if (VcastrConfig.isShowAbout) {
about(this, "About Vcastr 3.0", "http://code.google.com/p/vcastr/");
}
}
private function onLoaderComplete(e:Event) {
(e.target.loader.content as Sprite).addEventListener(VideoEvent.READY, onPlugInAddToStage, false, 0, true);
var plugInName:String = (e.target as LoaderInfo).loader.name;
deleteArrayElement(_unLoadPlugInNameArray, plugInName);
addChild(e.target.loader.content);
}
private function onPlugInAddToStage(e:Event):void {
checkInit();
}
private function checkInit():void {
if (_unLoadPlugInNameArray.length == 0 && VcastrConfig.dataXml) {
run();
dispatchEvent(new VideoEvent(VideoEvent.INIT, false, false, videoPlayer.state, videoPlayer.playheadTime));
}
}
private function initVar():void {
paramToVar(loaderInfo.parameters, VcastrConfig);
//_unLoadPlugInNameArray = VcastrConfig.plugIn;
}
private function configListener():void {
_videoPlayer.addEventListener(VideoEvent.STATE_CHANGE, onVideoPlayerStateChange, false, 0, true);
_videoPlayer.addEventListener(VideoEvent.COMPLETE, onVideoPlayerComplete, false, 0, true);
_videoPlayer.addEventListener(VideoEvent.READY, onVideoPlayerReady, false, 0, true);
_videoPlayer.addEventListener(VideoEvent.PLAYHEAD_UPDATE, onVideoPlayerPlayHeadUpdate, false, 0, true);
_videoPlayer.addEventListener(VideoEvent.PROGRESS, onVideoPlayerProgress, false, 0, true);
}
private function onVideoPlayerProgress(e:Event) {
dispatchEvent(e);
}
private function onVideoPlayerPlayHeadUpdate(e:Event) {
dispatchEvent(e);
}
private function onXmlLoaderComplete(e:Event) {
VcastrConfig.dataXml = new XML(e.target.data);
xmlToVar(VcastrConfig.dataXml.config[0],VcastrConfig)
checkInit();
}
private function run():void {
_videoXml = VcastrConfig.dataXml.item[_activeVideoId];
addChild(_centerBtn);
configListener();
if (VcastrConfig.controlPanelMode!=VcastrConfig.NONE) {
_defaultControlPanel = new DefaultControlPanel();
addChild(_defaultControlPanel);
}
stage.addChild(SimpleAlert.instance);
_videoPlayer.dataXml = _videoXml
}
private function onVideoPlayerStateChange(e:VideoEvent):void {
dispatchEvent(new VideoEvent(e.state, false, false, e.state, e.playheadTime));
}
private function onVideoPlayerComplete(e:VideoEvent):void {
next();
dispatchEvent(e);
}
private function onVideoPlayerReady(e:VideoEvent):void {
dispatchEvent(e);
}
public function playPause():void {
_videoPlayer.playPause();
}
public function play() {
_videoPlayer.play();
}
public function pause():void {
_videoPlayer.pause();
}
public function stop():void {
_videoPlayer.stop();
}
public function ff():void {
_videoPlayer.ff();
}
public function rew():void {
_videoPlayer.rew();
}
public function get videoPlayer():VideoPlayer {
return _videoPlayer;
}
public function next():void {
if (_activeVideoId < VcastrConfig.dataXml.item.length()-1) {
_activeVideoId++
_videoXml = VcastrConfig.dataXml.item[_activeVideoId];
VcastrConfig.isAutoPlay = true;
_videoPlayer.dataXml = _videoXml;
}
}
public function prev():void {
if (_activeVideoId > 0) {
_activeVideoId--
_videoXml = VcastrConfig.dataXml.item[_activeVideoId];
VcastrConfig.isAutoPlay = true;
_videoPlayer.dataXml = _videoXml;
}
}
public function get dataXml():XML {
return VcastrConfig.dataXml;
}
public function get videoXml():XML {
return _videoXml;
}
public function get playheadTime():Number {
return videoPlayer.playheadTime;
}
public function get totalTime():Number {
return videoPlayer.totalTime;
}
public function get bytesLoaded():Number {
return videoPlayer.bytesLoaded;
}
public function get bytesTotal():Number {
return videoPlayer.bytesTotal;
}
public function playerSizeTo(w:int,h:int):void {
_videoPlayer.setSize(w, h);
dispatchEvent(new VideoEvent(VideoEvent.LAYOUT_CHANGE, false, false, videoPlayer.state, videoPlayer.playheadTime));
}
public function playerMoveTo(px:int,py:int):void {
_videoPlayer.x = px;
_videoPlayer.y = py;
dispatchEvent(new VideoEvent(VideoEvent.LAYOUT_CHANGE, false, false, videoPlayer.state, videoPlayer.playheadTime));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -