2016-10-13 00:16:48 点击量:6 标签: 收藏本文
在本例中,创建 Video 和 NetStream 对象并调用 Video.attachNetStream() 和 NetStream.play() 方法的代码放在处理函数中。 仅当连接到 NetConnection 对象的尝试取得成功时才调用处理函数,即,当 netStatus 事件返回 info 对象(带有一个表示成功的 code 属性)时,才调用该处理函数。 建议您在调用 NetStream.play() 之前,等待连接成功。
- package {
- import flash.display.Sprite;
- import flash.events.NetStatusEvent;
- import flash.events.SecurityErrorEvent;
- import flash.media.Video;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.events.Event;
- public class NetConnectionExample extends Sprite {
- private var videoURL:String = "Video.flv";
- private var connection:NetConnection;
- private var stream:NetStream;
- public function NetConnectionExample() {
- connection = new NetConnection();
- connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
- connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
- connection.connect(null);
- }
- private function netStatusHandler(event:NetStatusEvent):void {
- switch (event.info.code) {
- case "NetConnection.Connect.Success":
- connectStream();
- break;
- case "NetStream.Play.StreamNotFound":
- trace("Stream not found: " + videoURL);
- break;
- }
- }
- private function securityErrorHandler(event:SecurityErrorEvent):void {
- trace("securityErrorHandler: " + event);
- }
- private function connectStream():void {
- var stream:NetStream = new NetStream(connection);
- stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
- stream.client = new CustomClient();
- var video:Video = new Video();
- video.attachNetStream(stream);
- stream.play(videoURL);
- addChild(video);
- }
- }
- }
- class CustomClient {
- public function onMetaData(info:Object):void {
- trace("CuPlayer.com提示:metadata: duration=" + info.duration +
" width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);- }
- public function onCuePoint(info:Object):void {
- trace("CuPlayer.com提示:cuepoint: time=" + info.time +
" name=" + info.name + " type=" + info.type);- }
- }
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室