2016-10-13 00:16:48 点击量:11 标签: 收藏本文
创建 Video 和 NetStream 对象并调用 Video.attachNetStream() 和 NetStream.play() 的代码放入处理函数。仅在试图连接 NetConnection 对象成功时调用处理函数,即,当 netStatus 事件返回一个 info 对象,该对象带有一个表示成功的 code 属性时,才调用该处理函数。建议先等待连接成功,然后再调用 NetStream.play()。
- package {
- import flash.display.Sprite;
- import flash.events.*;
- import flash.media.Video;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- public class VideoExample extends Sprite {
- private var videoURL:String = "Video.flv";
- private var connection:NetConnection;
- private var stream:NetStream;
- public function VideoExample() {
- 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("Unable to locate video: " + videoURL);
- break;
- }
- }
- private function connectStream():void {
- stream = new NetStream(connection);
- stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
- stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
- var video:Video = new Video();
- video.attachNetStream(stream);
- stream.play(videoURL);
- addChild(video);
- }
- private function securityErrorHandler(event:SecurityErrorEvent):void {
- trace("securityErrorHandler: " + event);
- }
- private function asyncErrorHandler(event:AsyncErrorEvent):void {
- // ignore AsyncErrorEvent events.
- }
- }
- }
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室