1. Define a window class:
Package
{
ImportFlash. display. Sprite;
Public class
LayerExtendsSprite
{
// Window layer
Protectedvar
_ Windowlayer: SPRITE;
Publicfunction
Layer ()
{
Init ();
}
Privatefunction
Init ():Void
{
_ Windowlayer =NewSprite ();
Addchild (_ windowlayer );
}
/**
* Window layer
*/
Publicfunction
GetWindowlayer (): Sprite
{
Return_ Windowlayer;
}
}
}
2. Declare a container variable:
Private var_container: SPRITE;
3. assign a value to the container variable:
PublicfunctionSetcontainer (container: SPRITE ):Void{
_ Container = container;
}
4. Play a video:
PublicfunctionPlayvideo ():Void
{
Buf. resetvideo ();
VaRVideo: Video =New
Video ();
Video. attachnetstream (BUF. NS );
_ Container. addchild (video );
}
Note: Buf is a custom video processing class, which requires the relevant netstream member variable. It is processed when a frame-by-frame video data is received, usage method _ ns. appendbytes (videoframe. streamdata );
Play the received real-time video frame, and the video class is mainly used to display the video, that is, the method video. attachnetstream (BUF. NS); the video class is associated with the relevant netstream
5. generally, the received video frame data does not contain the FLV Header Format, while the video data in the FLV format needs to be played in ActionScript. Therefore, the FLV header information must be added to the video, as follows:
VaRFirsttag: bytearray =New
Bytearray ();
Firsttag. endian = endian. big_endian;
// Video
Firsttag. writebyte (0x09 );
Firsttag. Position = 11;
// 4 bits: type of frame 1 => key frame + 4 bits: 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 );
VaRFirsttaglen: 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: I wrote an article at the beginning. Please forgive me. If you have any questions or communication, you can add your YY: 301558660
Reprinted please indicate the source: zhujian blog, http://blog.csdn.net/linyanwen99/article/details/8165662