Play local Video(flv mainly) in ActionScript3.0
来源:互联网 发布:淘宝权全民直播 编辑:程序博客网 时间:2024/06/10 03:55
Before going in-depth and develop complex application, we shuold clearify the basic mechanism of how Flash Player tackle with video files. It provide some facilities to access the media data through network, they are a serial of classes. The main ones are Video, NetStream and NetConnection. A picture is always worth sound words, following is a diagram depicts the relationship among some concepts and the correspending classes:
Not as implied as there names, Video class doesn't handle the manipulation of video indeed, instead, its responsiblity is just to display the content, it can be used to display different kind of video content, the source varies, may be a live stream from a camera, but we only explore the case that the video is a file stored on local hard disk. And NetStream is the one that used to control the video, such as playing, pausing, seeking and stop. It would be attached to a Video object, and it must relay on NetConnection object, to work.
And now we draw a rough sketch of code to demostrate how those classes work:
/* An experiment that to explore * how to play local video * in actionscript 3.0 * Created by Vincent Zhang, 11-July-2011 */import flash.media.Video;import flash.net.NetConnection;import flash.net.NetStream;import flash.events.NetStatusEvent;import flash.events.SecurityErrorEvent;import flash.events.IOErrorEvent;import flash.events.AsyncErrorEvent;// variable for storing duration of the video file,// may or may not be usedvar _duration:Number;// create video object to display the video content// and add it to display listvar _video:Video = new Video();addChild(_video);// create NetConnection object, connect it to null, means // no server designatedvar _connection:NetConnection = new NetConnection();_connection.addEventListener(NetStatusEvent.NET_STATUS, onStatus);_connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);_connection.addEventListener(IOErrorEvent.IO_ERROR, onIOError);_connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);_connection.connect(null);// create NetStream object with the NetConnection object,// attach it to Video object// then it can be use to play and control the video streamvar _stream:NetStream = new NetStream(_connection);_stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);_stream.addEventListener(IOErrorEvent.IO_ERROR, onIOError);_stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onAsyncError);_video.attachNetStream(_stream);// play the specific flv file// this function receive a string as parameter// to specify the url of the video file_stream.play("PICHONKUN.flv");// object play a role as listener// it is for fetching the meta data of the video file// such as W & H, duration and etc...var _clientObject:Object = new Object();_clientObject.onMetaData = metaDataListener;_stream.client = _clientObject;// handler function for listenerfunction metaDataListener(metaData:Object):void{_duration = metaData.duration;_video.width = metaData.width;_video.height = metaData.height;}// handler function for net connection statusfunction onStatus(__e:NetStatusEvent):void{trace(__e.info.code);if("NetStream.Play.Stop" == __e.info.code){_stream.play("stand-by-me.flv");}}// error handlersfunction onIOError(__e:IOErrorEvent):void{trace("IOErrorHandler: " + __e);}function onSecurityError(__e:SecurityErrorEvent):void{trace("securityErrorHandler: " + __e);}function onAsyncError(__e:AsyncErrorEvent):void{// ignore AsyncErrorEvent events.}
Since the video file resides locally, there is no server invlved, so the parameter passed to netstream.play() is null.
The statement
trace(__e.info.code);
inside onStatus() will output the followings:
NetConnection.Connect.SuccessNetStream.Play.StartNetStream.Buffer.FullNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.EmptyNetStream.Buffer.FlushNetStream.Play.StopNetStream.Play.StartNetStream.Buffer.FullNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.FlushNetStream.Buffer.EmptyNetStream.Buffer.FlushNetStream.Play.Stop
Finally, this sample program will go into a loop of playing stand-by-me.flv again and again.
fla link
- Play local Video(flv mainly) in ActionScript3.0
- Error events you must handle in play flv video
- MD5 in Actionscript3.0
- play video in Qt using GStreamer xvimagesink
- Custom Event in ActionScript3.0
- Clear Array in Actionscript3.0
- Garbage Collection in Actionscript3.0
- How to play video in cocos2dx with DirectShow
- How to play video with AVPlayerViewController (AVKit) in Swift
- Loop Through Object in Actionscript3.0
- Capture Keyboard Event in Actionscript3.0
- root, stage and timeline in ActionScript3.0
- Alternatives to Array in Actionscript3.0
- What is weak reference in Actionscript3.0?
- 【video】FLV封装原理
- 【Video】FLV封装原理
- 【video】FLV格式
- Video Capture and play
- 查询数据库中有多少行信息
- 十个供参考的移动应用设计思路
- 光脚丫学ASP.NET MVC(0004):在ASP.NET MVC中使用Forms身份验证
- .net 读取pdf文件方法
- objective-c学习笔记第九章《objective-c 中数组,字符串,集合》
- Play local Video(flv mainly) in ActionScript3.0
- 全局快门与卷帘式快门
- 将多个Excel文件批量导入某个Excel文件中
- stdafx.h在C++中起到的作用
- 固定窗口大小的方法
- ANDROID获取设备ID、型号及其它信息
- 窗口创建中的 WS_CLIPCHILDREN 和 WS_CLIPSBLINGS风格 细说
- AIX系统管理界面工具SMIT快捷方式
- define特殊用法