织梦CMS - 轻松建站从此开始!

罗索

JW flv Player修改版支持fms直播视频

jackyhwei 发布于 2011-05-29 21:26 点击:次 
群里好几个人问怎么直播视频文件,做了个简单的,未来还会更新一些功能,现在算是ntv0.1吧
TAG:

群里好几个人问怎么直播视频文件,做了个简单的,未来还会更新一些功能,现在算是ntv0.1吧

下载:点此下载NTV 0.1

(531k)(090104更新,之前的播放端少了个参数)

1. ntv文件夹放在 fms安装目录下的applications目录下

例如:

C:\Program Files\Adobe\Flash Media Server 3\applications\ntv

2. 把player和admin文件夹分别传到web可以访问的地方

例如:

www.rosoo.net/player

www.rosoo.net/admin

使用方法很简单:

管理端:

打开 你的地址/admin/admin.html

输入默认密码 admin (密码在ntv\main.asc 里改)

attachments/200812/26_181207_1.jpg

左边自动列出ntv\streams\_definst_ 下的所有视频文件

attachments/200812/26_181214_2.jpg

点击播放后,从 播放端

你的地址/player/player.html

就能看到视频播放了。

-------------------------------------------------------------------------------

为啥不贴代码?

目前功能很简单,代码没经过优化,未来版本会发代码。

这个FLV Player 是?

播放器是 JWPlayer 4.2 修改得来的,但任何播放器能播放这个流地址的 rtmp://localhost/ntv/flvlist 都是可以播放的

把JWPlayer 4.2播放器哪里修改了?

com\jeroenwijering\player\Model.as 中的loadModel 方法改成

  1. private function loadModel(typ:String):void { 
  2.     switch(typ) { 
  3.       case 'camera'
  4.         models[typ] = new CameraModel(this); 
  5.         break
  6.       case 'image'
  7.         models[typ] = new ImageModel(this); 
  8.         break
  9.       case 'sound'
  10.         if(config['streamer'] && config['streamer'].substr(0,4) == 'rtmp'
  11.         { 
  12.           if(String(config['live'])=="true"
  13.             { 
  14.                
  15.               models[typ] = new LiveModel(this); 
  16.             }else 
  17.             { 
  18.               models[typ] = new RTMPModel(this); 
  19.             } 
  20.         } else { 
  21.           models[typ] = new SoundModel(this); 
  22.         } 
  23.         break
  24.       case 'video'
  25.         if(config['streamer']) { 
  26.           if(config['streamer'].substr(0,4) == 'rtmp') { 
  27.             if(String(config['live'])=="true"
  28.             { 
  29.               models[typ] = new LiveModel(this); 
  30.             }else 
  31.             { 
  32.               models[typ] = new RTMPModel(this); 
  33.             } 
  34.              
  35.           } else { 
  36.             models[typ] = new HTTPModel(this); 
  37.           } 
  38.         } else { 
  39.           models[typ] = new VideoModel(this); 
  40.         } 
  41.         break
  42.       case 'youtube'
  43.         models[typ] = new YoutubeModel(this); 
  44.         break
  45.     } 
  46.   }; 

并在 com\jeroenwijering\models\ 中添加一个LiveModel类

  1. package com.jeroenwijering.models { 
  2.  
  3. import com.jeroenwijering.events.*; 
  4. import com.jeroenwijering.models.ModelInterface; 
  5. import com.jeroenwijering.player.Model; 
  6. import com.jeroenwijering.utils.NetClient; 
  7. import com.meychi.ascript.TEA; 
  8. import flash.display.DisplayObject; 
  9. import flash.events.*; 
  10. import flash.media.*; 
  11. import flash.net.*; 
  12. import flash.utils.*; 
  13.  
  14. public class LiveModel implements ModelInterface { 
  15.  
  16.   /** reference to the model. **/ 
  17.   private var model:Model; 
  18.   /** Video object to be instantiated. **/ 
  19.   private var video:Video; 
  20.   /** NetConnection object for setup of the video stream. **/ 
  21.   private var connection:NetConnection; 
  22.   /** NetStream instance that handles the stream IO. **/ 
  23.   private var stream:NetStream; 
  24.   /** Sound control object. **/ 
  25.   private var transform:SoundTransform; 
  26.   /** Interval ID for the time. **/ 
  27.   private var timeinterval:Number; 
  28.   /** Timeout ID for live stream subscription pings. **/ 
  29.   private var timeout:Number; 
  30.   /** Metadata have been received. **/ 
  31.   private var metadata:Boolean; 
  32.   
  33.   private var completeFlag:Boolean = false 
  34.  
  35.   /** Constructor; sets up the connection and display. **/ 
  36.   public function LiveModel(mod:Model):void { 
  37.      
  38.     model = mod; 
  39.     connection = new NetConnection(); 
  40.     connection.addEventListener(NetStatusEvent.NET_STATUS,statusHandler); 
  41.     connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,errorHandler); 
  42.     connection.addEventListener(IOErrorEvent.IO_ERROR,errorHandler); 
  43.     connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR,metaHandler); 
  44.      
  45.     connection.client = new NetClient(this); 
  46.     video = new Video(320,240); 
  47.     quality(model.config['quality']); 
  48.     transform = new SoundTransform(); 
  49.     model.config['mute'] == true ? volume(0): volume(model.config['volume']); 
  50.   }; 
  51.  
  52.   /** Catch security errors. **/ 
  53.   private function errorHandler(evt:ErrorEvent):void { 
  54.     model.sendEvent(ModelEvent.ERROR,{message:evt.text}); 
  55.   }; 
  56.  
  57.   /** xtract the current Stream from an RTMP URL **/ 
  58.   private function getID(url:String):String { 
  59.     if (url.substr(-4) == '.flv'){ 
  60.       url = url.substr(0,url.length-4); 
  61.     } 
  62.     return url; 
  63.   }; 
  64.  
  65.   /** Load content. **/ 
  66.   public function load():void { 
  67.     model.mediaHandler(video); 
  68.     connection.connect(model.config['streamer'],1); 
  69.     model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.BUFFERING}); 
  70.   }; 
  71.  
  72.   /** Catch noncritical errors. **/ 
  73.   private function metaHandler(evt:ErrorEvent):void { 
  74.     model.sendEvent(ModelEvent.META,{error:evt.text}); 
  75.   };
  76.   /** Pause playback. **/ 
  77.   public function pause():void {
  78.     stream.pause(); 
  79.     model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.PAUSED}); 
  80.   }; 
  81.  
  82.   /** Resume playing. **/ 
  83.   public function play():void {
  84.     stream.bufferTime = 2 
  85.     stream.resume(); 
  86.     model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.PLAYING});
  87.   }; 
  88.  
  89.   /** Change the smoothing mode. **/ 
  90.   public function quality(qua:Boolean):void { 
  91.     if(qua == true) { 
  92.       video.smoothing = true
  93.       video.deblocking = 3; 
  94.     } else { 
  95.       video.smoothing = false
  96.       video.deblocking = 1; 
  97.     } 
  98.   }; 
  99.  
  100.   /** Change the smoothing mode. **/ 
  101.   public function seek(pos:Number):void {}; 
  102.  
  103.   /** Set streaming object **/ 
  104.   public function setStream():void { 
  105.     var url = getID(model.playlist[model.config['item']]['file']); 
  106.     stream = new NetStream(connection); 
  107.     stream.addEventListener(NetStatusEvent.NET_STATUS,statusHandler); 
  108.     stream.addEventListener(IOErrorEvent.IO_ERROR,errorHandler); 
  109.     stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,metaHandler); 
  110.     stream.bufferTime = model.config['bufferlength']; 
  111.     stream.client = new NetClient(this); 
  112.     video.attachNetStream(stream); 
  113.     stream.soundTransform = transform; 
  114.     stream.play(url);
  115.     //clearInterval(timeinterval); 
  116.     //timeinterval = setInterval(timeHandler,100); 
  117.   };
  118.   /** Receive NetStream status updates. **/ 
  119.   private function statusHandler(evt:NetStatusEvent):void {
  120.     if(evt.info.code == "NetConnection.Connect.Success") {
  121. setStream();
  122.     } else if(evt.info.code == "NetConnection.Connect.Rejected"
  123.  || evt.info.code == "NetConnection.Connect.Failed") {
  124.       connection.close(); 
  125.      if(stream) { stream.close(); } 
  126.      video.attachNetStream(null); 
  127.       model.sendEvent(ModelEvent.ERROR,{message:"Stream not found: "
  128. + model.playlist[model.config['item']]['file']}); 
  129.     } else if(evt.info.code == "NetStream.Buffer.Full"){ 
  130.       if (model.config['state'] == ModelStates.BUFFERING) { 
  131.       model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.PLAYING}); 
  132.      } 
  133.       stream.bufferTime = 20 
  134.     } else if(evt.info.code == "NetStream.Buffer.Empty"){ 
  135.        if(model.config['state'] != ModelStates.BUFFERING) {
  136.         model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.BUFFERING}); 
  137.       }
  138.       if(completeFlag == true){ 
  139.        //ExternalInterface.call("playComplete"); 
  140.       completeFlag = false
  141.       }else{
  142.       stream.bufferTime=2
  143.      }
  144.     } else { 
  145.       //model.sendEvent(ModelEvent.META,{info:evt.info.code}); 
  146.     } 
  147.   }; 
  148.  
  149.   /** Destroy the stream. **/ 
  150.   public function stop():void {}; 
  151.   /** Set the volume level. **/ 
  152.   public function volume(vol:Number):void { 
  153.     transform.volume = vol/100; 
  154.     if(stream) { 
  155.       stream.soundTransform = transform; 
  156.     } 
  157.   }; 
  158. }; 

 

(陈新)
本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/201105/14365.html]
本文出处:nshen.net 作者:陈新
顶一下
(0)
0%
踩一下
(1)
100%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
将本文分享到微信
织梦二维码生成器
推荐内容