[AS3]as3.0封装的Video类
我们平常播放FLV视频要三个类,笔者感觉这样写比较麻烦。所以我的第一步就是从新封装Video类。让这个类和另外2个类封装到一起。好了这个封装的类放到了一个名为playermedia的文件夹内
我们平常播放FLV视频要三个类,笔者感觉这样写比较麻烦。所以我的第一步就是从新封装Video类。让这个类和另外2个类封装到一起。好了这个封装的类放到了一个名为playermedia的文件夹内,代码如下:
- package playermedia{
- import playermedia.CustomClient;
- import flash.media.SoundTransform;
- import flash.events.IOErrorEvent;
- import flash.events.NetStatusEvent;
- import flash.events.AsyncErrorEvent;
- import flash.net.NetConnection;
- import flash.net.NetStream;
- import flash.media.Video;
- public class Playervideo extends Video {
- private var netconnection:NetConnection;
- private var netstream:NetStream;
- private var video_url:String;
- private var videosound:SoundTransform;
- public static var video_time:Number=0;
- public function Playervideo():void {
- CustomClient.setdata(this);
- netconnection=new NetConnection ;
- netconnection.connect(null);
- netstream=new NetStream(netconnection);
- netstream.client=new CustomClient ;
- videosound = new SoundTransform();
- videosound.volume = 1;
- netstream.soundTransform = videosound;
- this.attachNetStream(netstream);
- netstream.checkPolicyFile = true;
- netconnection.addEventListener(NetStatusEvent.NET_STATUS,streamnotfound);
- netconnection.addEventListener(AsyncErrorEvent.ASYNC_ERROR,netmistake);
- netconnection.addEventListener(IOErrorEvent.IO_ERROR,mistake);
- netstream.addEventListener(IOErrorEvent.IO_ERROR,mistake);
- netstream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,netmistake);
- netstream.addEventListener(NetStatusEvent.NET_STATUS,streamnotfound);
- }
- private function netmistake(evt:AsyncErrorEvent):void {
- trace("CuPlayer.com提示:异步错误");
- }
- private function streamnotfound(evt:NetStatusEvent):void {
- switch (evt.info.code) {
- case "NetStream.Play.Stop" :
- CustomClient.stopvideo();
- break;
- case "NetStream.Play.Start" :
- trace("CuPlayer.com提示:视频开始播放");
- break;
- case "NetStream.Buffer.Empty" :
- trace("数据的接收速度不足以填充缓冲区。");
- break;
- case "NetStream.Buffer.Full" :
- trace("缓冲区已满并且流将开始播放。");
- CustomClient.secplay();
- break;
- case "NetStream.Buffer.Flush" :
- trace("数据已完成流式处理,剩余的缓冲区将被清空。");
- break;
- case "NetStream.Seek.Notify" :
- trace("CuPlayer.com提示:搜寻操作完成。");
- break;
- }
- }
- private function mistake(evt:IOErrorEvent):void {
- //CuPlayer.com提示:错误处理代码
- trace("错了!");
- }
- //CuPlayer.com提示:播放视频
- public function playvideo({
- netstream.play(url);
- video_url = url;
- }
- //CuPlayer.com提示:加载条进度百分比
- public function loadprogress():Number {
- return netstream.bytesLoaded / netstream.bytesTotal;
- }
- //视频的播放时间计算
- public function playtime():String {
- var streamminute:Number = Math.floor(netstream.time / 60);
- var smin_str:String;
- if (streamminute>=10) {
- smin_str = String(streamminute);
- } else {
- smin_str = "0" + streamminute;
- }
- var streamsecond:Number = Math.round(netstream.time % 60);
- var ssec_str:String;
- if (streamsecond>=10) {
- ssec_str = String(streamsecond);
- } else {
- ssec_str = "0" + streamsecond;
- }
- var newtime:String = smin_str + ":" + ssec_str;
- return newtime;
- }
- //设置视频音量
- public function setsound(sound_data:Number):void {
- videosound.volume = sound_data;
- netstream.soundTransform = videosound;
- }
- //播放或停止视频
- public function playstopvideo():void {
- netstream.togglePause();
- }
- //计算当前播放时间的百分比
- public function playvideonowtime():Number {
- return netstream.time / video_time;
- }
- //CuPlayer.com提示:跳转视频
- public function playtimevideo(whereplaytime:Number):void {
- netstream.seek(whereplaytime);
- netstream.play(video_url);
- netstream.togglePause();
- }
- public function playtimemyvideo(timevideo:Number):void{
- netstream.seek(timevideo);
- }
- }
- }
热门文章推荐
- 纯HLS(m3u8)跨平台技术(HLSPlayer,m3u8Player跨平台多终端)
- DiscuzX3.2酷播视频插件(dz论坛自定义视频插件带广告
- [微信视频]实现网站中的视频在微信平台上正常播放(超多组图)
- [rtsp]海康威视监控摄像头实现web端无插件监控实拍效果
- 很酷,酷播wordpress视频插件(支持PC/安卓/苹果跨平台播放)
- [组图]微信视频技术:支持微信视频直播和视频点播
- [AS3]as3.0的rtmp流媒体播放器写法源代码示例
- 一步一步教你制作FLV网页视频播放器
请稍候...