⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcastr3.as.svn-base

📁 使用as3.0重新写了播放器 播放器大小缩小,在21k左右 新参数和vcastr2.x不同 可以通过xml对播放器设置 界面更新 增加音量控制 留出了插件的接口
💻 SVN-BASE
字号:
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;
	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(MetadataEvent.METADATA_RECEIVED, onVideoPlayerMetadataReceive, false, 0, true);
			_videoPlayer.addEventListener(VideoEvent.READY, onVideoPlayerReady, false, 0, true);
			_videoPlayer.addEventListener(VideoEvent.PLAYHEAD_UPDATE, onVideoPlayerPlayHeadUpdate, false, 0, true);
			_videoPlayer.addEventListener(VideoProgressEvent.PROGRESS, onVideoPlayerProgress, false, 0, true);
			*/
			_videoPlayer.addEventListener(VideoEvent.STATE_CHANGE, onVideoPlayerStateChange, false, 0, true);
			_videoPlayer.addEventListener(VideoEvent.COMPLETE, onVideoPlayerComplete, false, 0, true);
			//_videoPlayer.addEventListener(MetadataEvent.METADATA_RECEIVED, onVideoPlayerMetadataReceive, 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 onVideoPlayerMetadataReceive(e:MetadataEvent) {
			
		//}
		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);		
			checkInit();
		}
		private function run():void {			
			_videoXml = VcastrConfig.dataXml.item[_activeVideoId];	
			addChild(_centerBtn);
			configListener();
			if (VcastrConfig.isShowControlPanel) {
				_defaultControlPanel = new DefaultControlPanel();
				addChild(_defaultControlPanel);				
			}
			_videoPlayer.url = _videoXml.source[0]
			stage.addChild(SimpleAlert.instance);
		}
		private function onVideoPlayerStateChange(e:VideoEvent):void { 
			dispatchEvent(new VideoEvent(e.state, false, false, e.state, e.playheadTime));
		}
		private function onVideoPlayerComplete(e:VideoEvent):void {
			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()) {
				_activeVideoId++
				_videoXml = VcastrConfig.dataXml.item[_activeVideoId];
				checkInit();
			}
		}
		public function prev():void {
			if (_activeVideoId > 0) {
				_activeVideoId--
				_videoXml = VcastrConfig.dataXml.item[_activeVideoId];
				checkInit();
			}
		}
		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 + -