Flash播放外部视频

一、播放外部视频

1、视频和Flash再同一目录,视频名字叫做 测试.flv

参考

https://jingyan.baidu.com/article/fc07f9897ed70612fee5197c.html

import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;

fscommand("fullscreen","true");

stop();

InitVars();
LoadMovie();

var theVideo:Video;//视频对象
var theNet:NetConnection;//连接对象
var theNets:NetStream;//数据流对象

function InitVars():void
{
	theVideo = new Video(1920,1080);
	theVideo.x = theVideo.y = 0;
	addChild(theVideo);

	theNet = new NetConnection();
	theNet.connect(null);

	theNets = new NetStream(theNet);
	theNets.client = this;

	theVideo.attachNetStream(theNets);
}

//加载并播放视频,并且监听整个播放状态过程。
function LoadMovie():void
{
	theNets.play("测试.flv");
	theNets.addEventListener(NetStatusEvent.NET_STATUS, onStatusHandler);
}

function onStatusHandler(e:NetStatusEvent):void
{
	var evtCode:String = e.info.code;
	switch (evtCode)
	{
		case "NetStream.Play.Start" :
			trace("开始播放");
			break;

		case "NetStream.Play.Empty" :
			trace("缓冲区为空");
			break;

		case "NetStream.Play.Full" :
			trace("缓冲区已满");
			break;

		case "NetStream.Play.StreamNotFound" :
			trace("没有找到文件");
			break;

		case "NetStream.Play.Stop" :
			trace("一次播放完毕,从头开始");
			theNets.seek(0);
			//RemoveVedio();
			break;
	}
}

//卸载视频
function RemoveVedio():void
{
	theNets.pause();
	theNets.dispose();
	theNet = null;
	theVideo.clear();
	removeChild(theVideo);
}

 

 

 

猜你喜欢

转载自blog.csdn.net/qq_40544338/article/details/86149552