一.定义一个窗口类:
package
{
import flash.display.Sprite;
public class Layerextends Sprite
{
//窗口层
protectedvar _windowLayer:Sprite;
publicfunction Layer()
{
init();
}
privatefunction init():void
{
_windowLayer =new Sprite();
addChild(_windowLayer);
}
/**
*窗口层
*/
publicfunction get windowLayer():Sprite
{
return _windowLayer;
}
}
}
二.声明一个容器变量:
private var_container:Sprite;
三.给该容器变量赋值:
publicfunction setContainer(container:Sprite):void{
_container = container;
}
四.播放视频:
publicfunction playVideo():void {
buf.resetVideo();
var video:Video =new Video();
video.attachNetStream(buf.ns);
_container.addChild(video);
}
说明:buf是一个自己定义的视频处理类,里面需要有相关的NetStream成员变量,在接收到一帧一帧的视频数据时,经过处理,使用方法_ns.appendBytes(videoFrame.streamData);
播放接收到的实时视频帧,而video类主要用于显示视频,即方法video.attachNetStream(buf.ns);把video类关联到相关的NetStream
五.通常接收到的视频帧数据不包含flv的头格式,而在actionscript中需要播放的是flv格式的视频数据,所以,通常要为视频加上flv的头信息,如下:
var firstTag:ByteArray =new ByteArray();
firstTag.endian= Endian.BIG_ENDIAN;
//video
firstTag.writeByte(0x09);
firstTag.position = 11;
//4bits:type of frame 1 => key frame + 4bits:CodecID 7 => AVC
firstTag.writeByte(0x17);
//AVCPacketType 0 => AVC sequence header
firstTag.writeByte(0x00);
//Composition time, 3 bytes 0 for the firsttag
firstTag.writeByte(0x00);
firstTag.writeByte(0x00);
firstTag.writeByte(0x00);
//TODOfirstTag.writeBytes(avcCfg);
var firstTagLen:uint = firstTag.length;
firstTag.writeUnsignedInt(firstTagLen);
firstTag.position = 1;
//3-byte DataSize
firstTag.writeByte( ((firstTagLen - 11)>> 16) & 0xff);
firstTag.writeByte( ((firstTagLen - 11)>> 8) & 0xff);
firstTag.writeByte( ((firstTagLen -11) ) & 0xff);
PS:初写文章,文笔生涩之处,各位请见谅,若有疑问或者交流的,可加本人YY号:301558660
转载请注明出处:山水间博客,http://blog.csdn.net/linyanwen99/article/details/8165662