ActionScript 3 AS3 FLVPlayback和FLVPlaybackCaptioning演示

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3 FLVPlayback和FLVPlaybackCaptioning演示相关的知识,希望对你有一定的参考价值。

// IMPORT CLASSES
import flash.events.MouseEvent;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.HTTPStatusEvent;
import flash.events.SecurityErrorEvent;
import fl.video.VideoEvent;
import fl.video.VideoState;
import fl.video.FLVPlayback;
import fl.video.FLVPlaybackCaptioning;
import fl.video.VideoProgressEvent;
import fl.video.CaptionChangeEvent;
import fl.video.CaptionTargetEvent;

// OUTPUT FLVPLAYBACK NAD CAPTIONING COMPONENT VERSION NUMBERS
trace("FLVPlayback.VERSION: "+FLVPlayback.VERSION);
trace("FLVPlaybackCaptioning.VERSION: "+FLVPlaybackCaptioning.VERSION);

// DEFINE VARIABLES
var flvFilename:String = "sample_video.flv";
var flvPath:String = "";
var captionsFilename:String = "captions_en.xml";
var captionsPath:String = "";
var flvPlayback:FLVPlayback;
var flvPlaybackCaptioning:FLVPlaybackCaptioning;

// SET FLVPLAYBACK PROPERTIES
flvPlayback = new FLVPlayback();
flvPlayback.x = 0;
flvPlayback.y = 0;
flvPlayback.width = 740;
flvPlayback.height = 416;
flvPlayback.fullScreenTakeOver = false;
flvPlayback.autoPlay = false;
flvPlayback.alpha = 1;
flvPlayback.autoRewind = false;
flvPlayback.isLive = false;
flvPlayback.skin = null;
flvPlayback.source = flvPath + flvFilename;

// DEFINE CONTROL BUTTONS
flvPlayback.playPauseButton = playPauseBtn;
flvPlayback.stopButton = stopBtn;
flvPlayback.backButton = backBtn;
flvPlayback.forwardButton = forwardBtn;
flvPlayback.fullScreenButton = fullScreenBtn;
flvPlayback.muteButton = muteBtn;
flvPlayback.volumeBar = volumeBar;
flvPlayback.seekBar = seekBar;

flvPlaybackCaptioning = new FLVPlaybackCaptioning();
flvPlaybackCaptioning.flvPlayback = flvPlayback;
flvPlaybackCaptioning.source = captionsPath + captionsFilename;;
flvPlaybackCaptioning.autoLayout = true;
flvPlaybackCaptioning.showCaptions = false; 

// ADD EVENT LISTENERS FOR FLVPLAYBACK COMPONENT
flvPlayback.addEventListener(VideoEvent.AUTO_REWOUND, onFlvPlayback_AUTO_REWOUND);
flvPlayback.addEventListener(VideoEvent.BUFFERING_STATE_ENTERED, onFlvPlayback_BUFFERING_STATE_ENTERED);
flvPlayback.addEventListener(VideoEvent.CLOSE, onFlvPlayback_CLOSE);
flvPlayback.addEventListener(VideoEvent.COMPLETE, onFlvPlayback_COMPLETE);
flvPlayback.addEventListener(VideoEvent.FAST_FORWARD, onFlvPlayback_FAST_FORWARD);
flvPlayback.addEventListener(VideoEvent.PAUSED_STATE_ENTERED, onFlvPlayback_PAUSED_STATE_ENTERED);
flvPlayback.addEventListener(VideoEvent.PLAYHEAD_UPDATE, onFlvPlayback_PLAYHEAD_UPDATE);
flvPlayback.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, onFlvPlayback_PLAYING_STATE_ENTERED);
flvPlayback.addEventListener(VideoEvent.READY, onFlvPlayback_READY);
flvPlayback.addEventListener(VideoEvent.REWIND, onFlvPlayback_REWIND);
flvPlayback.addEventListener(VideoEvent.SCRUB_FINISH, onFlvPlayback_SCRUB_FINISH);
flvPlayback.addEventListener(VideoEvent.SCRUB_START, onFlvPlayback_SCRUB_START);
flvPlayback.addEventListener(VideoEvent.SEEKED, onFlvPlayback_SEEKED);
flvPlayback.addEventListener(VideoEvent.SKIN_LOADED, onFlvPlayback_SKIN_LOADED);
flvPlayback.addEventListener(VideoEvent.STATE_CHANGE, onFlvPlayback_STATE_CHANGE);
flvPlayback.addEventListener(VideoEvent.STOPPED_STATE_ENTERED, onFlvPlayback_STOPPED_STATE_ENTERED);
flvPlayback.addEventListener(VideoProgressEvent.PROGRESS, onFlvPlayback_PROGRESS);

// ADD EVENT LISTENERS FOR FLVPLAYBACK CAPTIONING COMPONENT
flvPlaybackCaptioning.addEventListener(CaptionChangeEvent.CAPTION_CHANGE, onFlvPlaybackCaptioning_CAPTION_CHANGE);
flvPlaybackCaptioning.addEventListener(CaptionTargetEvent.CAPTION_TARGET_CREATED, onFlvPlaybackCaptioning_CAPTION_TARGET_CREATED);
flvPlaybackCaptioning.addEventListener(Event.COMPLETE, onFlvPlaybackCaptioning_COMPLETE);
flvPlaybackCaptioning.addEventListener(HTTPStatusEvent.HTTP_STATUS, onFlvPlaybackCaptioning_HTTP_STATUS);
flvPlaybackCaptioning.addEventListener(IOErrorEvent.IO_ERROR, onFlvPlaybackCaptioning_IO_ERROR);
flvPlaybackCaptioning.addEventListener(Event.OPEN, onFlvPlaybackCaptioning_OPEN);
flvPlaybackCaptioning.addEventListener(ProgressEvent.PROGRESS, onFlvPlaybackCaptioning_PROGRESS);
flvPlaybackCaptioning.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onFlvPlaybackCaptioning_SECURITY_ERROR);

// ADD TO STAGE
addChild(flvPlayback);
addChild(flvPlaybackCaptioning);
addChild(bufferingBar);

// DECLARE EVENT HANDLERS
function onFlvPlayback_AUTO_REWOUND(event:VideoEvent):void {
	trace("onFlvPlayback_AUTO_REWOUND()");
}

function onFlvPlayback_BUFFERING_STATE_ENTERED(event:VideoEvent):void {
	trace("onFlvPlayback_BUFFERING_STATE_ENTERED()");
	bufferingBar.visible = true;
}

function onFlvPlayback_CLOSE(event:VideoEvent):void {
	trace("onFlvPlayback_CLOSE()");
}

function onFlvPlayback_COMPLETE(event:VideoEvent):void {
	trace("onFlvPlayback_COMPLETE()");
	bufferingBar.visible = false;
}

function onFlvPlayback_FAST_FORWARD(event:VideoEvent):void {
	trace("onFlvPlayback_FAST_FORWARD()");
}

function onFlvPlayback_PAUSED_STATE_ENTERED(event:VideoEvent):void {
	trace("onFlvPlayback_PAUSED_STATE_ENTERED()");
}

function onFlvPlayback_PLAYHEAD_UPDATE(event:VideoEvent):void {
	//trace("onFlvPlayback_PLAYHEAD_UPDATE()");
}

function onFlvPlayback_PLAYING_STATE_ENTERED(event:VideoEvent):void {
	trace("onFlvPlayback_PLAYING_STATE_ENTERED()");
	bufferingBar.visible = false;
}

function onFlvPlayback_READY(event:VideoEvent):void {
	trace("onFlvPlayback_READY()");
	bufferingBar.visible = false;
}

function onFlvPlayback_REWIND(event:VideoEvent):void {
	trace("onFlvPlayback_REWIND()");
}

function onFlvPlayback_SCRUB_FINISH(event:VideoEvent):void {
	trace("onFlvPlayback_SCRUB_FINISH()");
}

function onFlvPlayback_SCRUB_START(event:VideoEvent):void {
	trace("onFlvPlayback_SCRUB_START()");
}

function onFlvPlayback_SEEKED(event:VideoEvent):void {
	trace("onFlvPlayback_SEEKED()");
}

function onFlvPlayback_SKIN_LOADED(event:VideoEvent):void {
	trace("onFlvPlayback_SKIN_LOADED()");
}

function onFlvPlayback_STATE_CHANGE(event:VideoEvent):void {
	trace("onFlvPlayback_STATE_CHANGE()");
	
	switch (flvPlayback.state) {
		case VideoState.BUFFERING:
			trace ("flvPlayback.state == VideoState.BUFFERING");
			break;
		case VideoState.CONNECTION_ERROR:
			trace ("flvPlayback.state == VideoState.CONNECTION_ERROR");
			break;
		case VideoState.DISCONNECTED:
			trace ("flvPlayback.state == VideoState.DISCONNECTED");
			break;
		case VideoState.LOADING:
			trace ("flvPlayback.state == VideoState.LOADING");
			break;
		case VideoState.PAUSED:
			trace ("flvPlayback.state == VideoState.PAUSED");
			break;
		case VideoState.PLAYING:
			trace ("flvPlayback.state == VideoState.PLAYING");
			break;
		case VideoState.RESIZING:
			trace ("flvPlayback.state == VideoState.RESIZING");
			break;
		case VideoState.REWINDING:
			trace ("flvPlayback.state == VideoState.REWINDING");
			break;
		case VideoState.SEEKING:
			trace ("flvPlayback.state == VideoState.SEEKING");
			break;
		case VideoState.STOPPED:
			trace ("flvPlayback.state == VideoState.STOPPED");
			break;
		default:
			trace("flvPlayback.state: "+flvPlayback.state);
	}
	
}

function onFlvPlayback_STOPPED_STATE_ENTERED(event:VideoEvent):void {
	trace("onFlvPlayback_STOPPED_STATE_ENTERED()");
}

function onFlvPlayback_PROGRESS(event:VideoProgressEvent):void {
	trace("onFlvPlayback_PROGRESS()");
	//trace("event.target.bytesLoaded: "+event.target.bytesLoaded);
	//trace("event.target.bytesTotal: "+event.target.bytesTotal+" ("+(Math.floor(((event.target.bytesTotal/1024/ 1024)*100))/100)+" MB)");
	var total:Number = event.target.bytesTotal;
	var part:Number = event.target.bytesLoaded;
	var percentage:Number = part / total;
	var percentageFormatted:String = Math.floor(percentage * 100)+"%";
	trace(percentageFormatted+" loaded");
}

function onFlvPlaybackCaptioning_CAPTION_CHANGE(event:CaptionChangeEvent):void {
	trace("onFlvPlaybackCaptioning_CAPTION_CHANGE()");
	var removeHtmlRegExp:RegExp = new RegExp("<[^<]+?>", "gi");
	if (event.added) {
		var objA:Object = event.captionCuePointObject;
		for (var i in objA){
			trace(i+": "+objA[i]);
			if (i == "parameters") {
				var objB:Object = objA[i];
				for (var j in objB){
					trace(j+": "+objB[j]);
					if (j == "text") {
						trace(objB[j].replace(removeHtmlRegExp, ""));
					}
				}
			}
		}
	}
}

function onFlvPlaybackCaptioning_CAPTION_TARGET_CREATED(event:CaptionTargetEvent):void {
	trace("onFlvPlaybackCaptioning_CAPTION_TARGET_CREATED()");
}

function onFlvPlaybackCaptioning_COMPLETE(event:Event):void {
	trace("onFlvPlaybackCaptioning_COMPLETE()");
}

function onFlvPlaybackCaptioning_HTTP_STATUS(event:HTTPStatusEvent):void {
	trace("onFlvPlaybackCaptioning_HTTP_STATUS()");
	trace("event.status: "+event.status);
}

function onFlvPlaybackCaptioning_IO_ERROR(event:IOErrorEvent):void {
	trace("onFlvPlaybackCaptioning_IO_ERROR()");
	trace("event.text: "+event.text);
}

function onFlvPlaybackCaptioning_OPEN(event:Event):void {
	trace("onFlvPlaybackCaptioning_OPEN()");
}

function onFlvPlaybackCaptioning_PROGRESS(event:ProgressEvent):void {
	trace("onFlvPlaybackCaptioning_PROGRESS()");
}

function onFlvPlaybackCaptioning_SECURITY_ERROR(event:SecurityErrorEvent):void {
	trace("onFlvPlaybackCaptioning_SECURITY_ERROR()");
	trace("event.text: "+event.text);
}



// The 'captions_en.xml' file looks like this ...
//<?xml version="1.0" encoding="UTF-8"?>
//<tt xmlns="http://www.w3.org/2006/04/ttaf1" xmlns:tts="http://www.w3.org/2006/04/ttaf1#styling">
//	<head>
//		<styling>
//			<style id="1" tts:textAlign="center" tts:fontFamily="_sans" tts:fontSize="16" tts:fontWeight="bold" tts:color="#FFFFFFFF"/>
//			<style id="2" tts:backgroundColor="#00000000"/>
//			<style id="3" tts:backgroundColor="#000000FF"/>
//			<style id="trans" style="1 2"/>
//			<style id="opaq" style="1 3"/>
//		</styling>
//	</head>
//	<body>
//		<div>
//			<!--
//			<p begin="00:00:00.20" dur="00:00:04.00" style="opaq">Nero is a Lionfish<br />(<span tts:fontStyle="italic">Pterois volitans</span>),</p>
//			<p begin="00:00:09.00" dur="00:00:02.00" style="trans">at home in his reef aquarium.</p>
//			-->
//
//			<p begin="00:00:01.000" style="trans">Hi John, Hi James,</p>
//			<p begin="00:00:03.369" style="trans">This is just a test to what a talking head shot would look like.</p>
//			<p begin="00:00:07.340" style="trans">Don't really know what to say, maybe I could sing a song for you.</p>
//			<p begin="00:00:11.833" style="trans">Having two small children, the only songs I really know are<br />things like Ba Ba Black Sheep and Incy Wincy Spider.</p>
//			<p begin="00:00:22.047" style="trans">Anyway, if I just move a little bit, from side to side.</p>
//			<p begin="00:00:28.133" style="trans">And maybe I'll just say the alphabet and then we can check syncing.</p>
//			<p begin="00:00:33.724" style="trans">A, B, C, D, E, F, G ...</p>
//			<p begin="00:00:38.791" style="trans">... H, I, J, K, L, M, N, O, P ...</p>
//			<p begin="00:00:42.240" style="trans">... Q, R, S, T, U, V ...</p>
//			<p begin="00:00:45.844" style="trans">... W, X, Y and Z</p>
//			<p begin="00:00:49.188" style="trans">Now I know my ABC, next time won't you sing with me.</p>
//			<p begin="00:00:56.450" style="trans">Hooray! I know my alphabet. All good.</p>
//			<p begin="00:01:00.656" style="trans">Ok, I'm going to sign-off now and I'll send this to you once I have popped it in to the demo.</p>
//			<p begin="00:01:06.377" style="trans">And we can test it on the Archos's.</p>
//			<p begin="00:01:08.388" style="trans">Ok, bye.</p>
//		</div>
//	</body>
//</tt>

以上是关于ActionScript 3 AS3 FLVPlayback和FLVPlaybackCaptioning演示的主要内容,如果未能解决你的问题,请参考以下文章

[ActionScript 3.0] AS3.0 水面波纹效果

ActionScript 3 AS3:使用SWFObject2和AS3传递变量

ActionScript 3 克隆数组(AS3)

ActionScript 3 AS3序列化

ActionScript 3 As3初始上限

ActionScript 3 AS3 HTML清理