代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
AS
】
简单流媒体播放器
作者:
芷君
/ 发布于
2014/11/4
/
1019
package { import flash.events.*; import flash.media.Video; import flash.display.Sprite; import flash.net.*; import flash.text.TextField; import fl.controls.Button; public class StreamingVideoPlayer extends Sprite { private var _videoURL:String; private var _video:Video; private var _vidDuration:Number; private var _vidXmax:Number; private var _vidYmax:Number; private var _vidWidth:Number; private var _vidHeight:Number; private var _main_nc:NetConnection = new NetConnection(); private var _serverLoc:String; private var _ns:NetStream; private var _start_btn:Button; /* ------------Contructors/Initialization-----------*/ public function StreamingVideoPlayer(serverLoc:String, flvLocation:String,vidDuration:Number,vidXmax:Number, vidYmax:Number):void { //set video params _videoURL = flvLocation; _vidDuration = vidDuration; _vidXmax = vidXmax; _vidYmax = vidYmax; //add eventListeners to NetConnection and connect _main_nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); _main_nc.addEventListener( SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); _main_nc.connect(serverLoc); } private function onNetStatus(event:Object):void { //handles NetConnection and NetStream status events switch (event.info.code) { case "NetConnection.Connect.Success": //play stream if connection successful connectStream(); break; case "NetStream.Play.StreamNotFound": //error if stream file not found in //location specified trace("Stream not found: " + _videoURL); break; case "NetStream.Play.Stop": //do if video is stopped videoPlayComplete(); break; } //trace(event.info.code); } /* -------------------Connection------------------- */ private function connectStream():void { //netstream object _ns = new NetStream(_main_nc); _ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler); _ns.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus); //other event handlers assigned //to the netstream client property var custom_obj:Object = new Object(); custom_obj.onMetaData = onMetaDataHandler; custom_obj.onCuePoint = onCuePointHandler; custom_obj.onPlayStatus = playStatus; _ns.client = custom_obj; //attach netstream to the video object _video = new Video(_vidXmax,_vidYmax); _video.attachNetStream(_ns); //video position could be parameterized but hardcoded //here to account for optional movie frame border _video.x = 1; _video.y = 1; addChild(_video); setVideoInit(); _ns.play(_videoURL); } /* -------------NetStream actions and events-------------- */ private function videoPlayComplete():void { setVideoInit(); } private function setVideoInit():void { _ns.play(_videoURL); _ns.pause(); _ns.seek(_vidDuration/2); addStartBtn(); } private function playStatus(event:Object):void { //handles onPlayStatus complete event if available switch (event.info.code) { case "NetStream.Play.Complete": //do if video play completes videoPlayComplete(); break; } //trace(event.info.code); } private function playFlv(event:MouseEvent):void { _ns.play(_videoURL); //_ns.seek(192); //used for testing removeChild(_start_btn); } private function pauseFlv(event:MouseEvent):void { _ns.pause(); } /* ---------Buttons, labels, and other assets------------- */ //could be placed in it's own VideoControler class private function addStartBtn():void { _start_btn = new Button(); _start_btn.width = 80; _start_btn.x = (_vidXmax-_start_btn.width)/2+_video.x; _start_btn.y = (_vidYmax-_start_btn.height)/2+_video.y; _start_btn.label = "Start Video"; _start_btn.addEventListener(MouseEvent.CLICK,playFlv); //addChild(_start_btn); } /* -----------------Information handlers---------------- */ private function onMetaDataHandler(metaInfoObj:Object):void { _video.width = metaInfoObj.width; _vidWidth = metaInfoObj.width; _video.height = metaInfoObj.height; _vidHeight = metaInfoObj.height; //trace("metadata: duration=" + metaInfoObj.duration + //"width=" + metaInfoObj.width + " height=" + //metaInfoObj.height + " framerate=" + //metaInfoObj.framerate); } private function onCuePointHandler(cueInfoObj:Object):void { //trace("cuepoint: time=" + cueInfoObj.time + " name=" + //cueInfoObj.name + " type=" + cueInfoObj.type); } /* -----------------------Error handlers------------------------ */ private function securityErrorHandler(event:SecurityErrorEvent): void { trace("securityErrorHandler: " + event); } private function asyncErrorHandler(event:AsyncErrorEvent):void { trace(event.text); } } }
试试其它关键字
流媒体
播放器
同语言下
.
C语言代码统计工具
.
排序集合中的元素
.
显示和隐藏隐含文件
.
ActionScript将颜色转换成16进制
.
把应用程序标题设置为版本号
.
异步读取文件
.
生成指定范围的随机数
.
定时器范例
.
返回当前SWF文件所在页面的url
.
通过get方式发送或者请求数据
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
芷君
贡献的其它代码
(
38
)
.
把应用程序标题设置为版本号
.
异步读取文件
.
生成指定范围的随机数
.
定时器范例
.
返回当前SWF文件所在页面的url
.
通过get方式发送或者请求数据
.
清除url里的http和https
.
智能缩放背景
.
生成随机boolean值
.
创建Grid表格
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3