JW flv Player修改版支持fms直播视频
群里好几个人问怎么直播视频文件,做了个简单的,未来还会更新一些功能,现在算是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.nshen.net/player
www.nshen.net/admin
使用方法很简单:
管理端:
打开 你的地址/admin/admin.html
输入默认密码 admin (密码在ntv\main.asc 里改)
左边自动列出ntv\streams\_definst_ 下的所有视频文件
点击播放后,从 播放端
你的地址/player/player.html
就能看到视频播放了。
-------------------------------------------------------------------------------
为啥不贴代码?
目前功能很简单,代码没经过优化,未来版本会发代码。
这个FLV Player 是?
播放器是 JWPlayer 4.2 修改得来的,但任何播放器能播放这个流地址的 rtmp://localhost/ntv/flvlist 都是可以播放的
把JWPlayer 4.2播放器哪里修改了?
com\jeroenwijering\player\Model.as 中的loadModel 方法改成
private function loadModel(typ:String):void {
switch(typ) {
case 'camera':
models[typ] = new CameraModel(this);
break;
case 'image':
models[typ] = new ImageModel(this);
break;
case 'sound':
if(config['streamer'] && config['streamer'].substr(0,4) == 'rtmp')
{
if(String(config['live'])=="true")
{
models[typ] = new LiveModel(this);
}else
{
models[typ] = new RTMPModel(this);
}
} else {
models[typ] = new SoundModel(this);
}
break;
case 'video':
if(config['streamer']) {
if(config['streamer'].substr(0,4) == 'rtmp') {
if(String(config['live'])=="true")
{
models[typ] = new LiveModel(this);
}else
{
models[typ] = new RTMPModel(this);
}
} else {
models[typ] = new HTTPModel(this);
}
} else {
models[typ] = new VideoModel(this);
}
break;
case 'youtube':
models[typ] = new YoutubeModel(this);
break;
}
};
switch(typ) {
case 'camera':
models[typ] = new CameraModel(this);
break;
case 'image':
models[typ] = new ImageModel(this);
break;
case 'sound':
if(config['streamer'] && config['streamer'].substr(0,4) == 'rtmp')
{
if(String(config['live'])=="true")
{
models[typ] = new LiveModel(this);
}else
{
models[typ] = new RTMPModel(this);
}
} else {
models[typ] = new SoundModel(this);
}
break;
case 'video':
if(config['streamer']) {
if(config['streamer'].substr(0,4) == 'rtmp') {
if(String(config['live'])=="true")
{
models[typ] = new LiveModel(this);
}else
{
models[typ] = new RTMPModel(this);
}
} else {
models[typ] = new HTTPModel(this);
}
} else {
models[typ] = new VideoModel(this);
}
break;
case 'youtube':
models[typ] = new YoutubeModel(this);
break;
}
};
并在 com\jeroenwijering\models\ 中添加一个LiveModel类
package com.jeroenwijering.models {
import com.jeroenwijering.events.*;
import com.jeroenwijering.models.ModelInterface;
import com.jeroenwijering.player.Model;
import com.jeroenwijering.utils.NetClient;
import com.meychi.ascript.TEA;
import flash.display.DisplayObject;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import flash.utils.*;
public class LiveModel implements ModelInterface {
/** reference to the model. **/
private var model:Model;
/** Video object to be instantiated. **/
private var video:Video;
/** NetConnection object for setup of the video stream. **/
private var connection:NetConnection;
/** NetStream instance that handles the stream IO. **/
private var stream:NetStream;
/** Sound control object. **/
private var transform:SoundTransform;
/** Interval ID for the time. **/
private var timeinterval:Number;
/** Timeout ID for live stream subscription pings. **/
private var timeout:Number;
/** Metadata have been received. **/
private var metadata:Boolean;
private var completeFlag:Boolean = false
/** Constructor; sets up the connection and display. **/
public function LiveModel(mod:Model):void {
model = mod;
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS,statusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,errorHandler);
connection.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR,metaHandler);
connection.client = new NetClient(this);
video = new Video(320,240);
quality(model.config['quality']);
transform = new SoundTransform();
model.config['mute'] == true ? volume(0): volume(model.config['volume']);
};
/** Catch security errors. **/
private function errorHandler(evt:ErrorEvent):void {
model.sendEvent(ModelEvent.ERROR,{message:evt.text});
};
/** xtract the current Stream from an RTMP URL **/
private function getID(url:String):String {
if (url.substr(-4) == '.flv'){
url = url.substr(0,url.length-4);
}
return url;
};
/** Load content. **/
public function load():void {
model.mediaHandler(video);
connection.connect(model.config['streamer'],1);
model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.BUFFERING});
};
/** Catch noncritical errors. **/
private function metaHandler(evt:ErrorEvent):void {
model.sendEvent(ModelEvent.META,{error:evt.text});
};
/** Pause playback. **/
public function pause():void {
stream.pause();
model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.PAUSED});
};
/** Resume playing. **/
public function play():void {
stream.bufferTime = 2
stream.resume();
model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.PLAYING});
};
/** Change the smoothing mode. **/
public function quality(qua:Boolean):void {
if(qua == true) {
video.smoothing = true;
video.deblocking = 3;
} else {
video.smoothing = false;
video.deblocking = 1;
}
};
/** Change the smoothing mode. **/
public function seek(pos:Number):void {
};
/** Set streaming object **/
public function setStream():void {
var url = getID(model.playlist[model.config['item']]['file']);
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS,statusHandler);
stream.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,metaHandler);
stream.bufferTime = model.config['bufferlength'];
stream.client = new NetClient(this);
video.attachNetStream(stream);
stream.soundTransform = transform;
stream.play(url);
//clearInterval(timeinterval);
//timeinterval = setInterval(timeHandler,100);
};
/** Receive NetStream status updates. **/
private function statusHandler(evt:NetStatusEvent):void {
if(evt.info.code == "NetConnection.Connect.Success") {
setStream();
} else if(evt.info.code == "NetConnection.Connect.Rejected" || evt.info.code == "NetConnection.Connect.Failed") {
connection.close();
if(stream) { stream.close(); }
video.attachNetStream(null);
model.sendEvent(ModelEvent.ERROR,{message:"Stream not found: "+ model.playlist[model.config['item']]['file']});
} else if(evt.info.code == "NetStream.Buffer.Full"){
if (model.config['state'] == ModelStates.BUFFERING) {
model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.PLAYING});
}
stream.bufferTime = 20
} else if(evt.info.code == "NetStream.Buffer.Empty"){
if(model.config['state'] != ModelStates.BUFFERING) {
model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.BUFFERING});
}
if(completeFlag == true){
//ExternalInterface.call("playComplete");
completeFlag = false
}else{
stream.bufferTime=2
}
} else {
//model.sendEvent(ModelEvent.META,{info:evt.info.code});
}
};
/** Destroy the stream. **/
public function stop():void {
};
/** Set the volume level. **/
public function volume(vol:Number):void {
transform.volume = vol/100;
if(stream) {
stream.soundTransform = transform;
}
};
};
}
import com.jeroenwijering.events.*;
import com.jeroenwijering.models.ModelInterface;
import com.jeroenwijering.player.Model;
import com.jeroenwijering.utils.NetClient;
import com.meychi.ascript.TEA;
import flash.display.DisplayObject;
import flash.events.*;
import flash.media.*;
import flash.net.*;
import flash.utils.*;
public class LiveModel implements ModelInterface {
/** reference to the model. **/
private var model:Model;
/** Video object to be instantiated. **/
private var video:Video;
/** NetConnection object for setup of the video stream. **/
private var connection:NetConnection;
/** NetStream instance that handles the stream IO. **/
private var stream:NetStream;
/** Sound control object. **/
private var transform:SoundTransform;
/** Interval ID for the time. **/
private var timeinterval:Number;
/** Timeout ID for live stream subscription pings. **/
private var timeout:Number;
/** Metadata have been received. **/
private var metadata:Boolean;
private var completeFlag:Boolean = false
/** Constructor; sets up the connection and display. **/
public function LiveModel(mod:Model):void {
model = mod;
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS,statusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,errorHandler);
connection.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR,metaHandler);
connection.client = new NetClient(this);
video = new Video(320,240);
quality(model.config['quality']);
transform = new SoundTransform();
model.config['mute'] == true ? volume(0): volume(model.config['volume']);
};
/** Catch security errors. **/
private function errorHandler(evt:ErrorEvent):void {
model.sendEvent(ModelEvent.ERROR,{message:evt.text});
};
/** xtract the current Stream from an RTMP URL **/
private function getID(url:String):String {
if (url.substr(-4) == '.flv'){
url = url.substr(0,url.length-4);
}
return url;
};
/** Load content. **/
public function load():void {
model.mediaHandler(video);
connection.connect(model.config['streamer'],1);
model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.BUFFERING});
};
/** Catch noncritical errors. **/
private function metaHandler(evt:ErrorEvent):void {
model.sendEvent(ModelEvent.META,{error:evt.text});
};
/** Pause playback. **/
public function pause():void {
stream.pause();
model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.PAUSED});
};
/** Resume playing. **/
public function play():void {
stream.bufferTime = 2
stream.resume();
model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.PLAYING});
};
/** Change the smoothing mode. **/
public function quality(qua:Boolean):void {
if(qua == true) {
video.smoothing = true;
video.deblocking = 3;
} else {
video.smoothing = false;
video.deblocking = 1;
}
};
/** Change the smoothing mode. **/
public function seek(pos:Number):void {
};
/** Set streaming object **/
public function setStream():void {
var url = getID(model.playlist[model.config['item']]['file']);
stream = new NetStream(connection);
stream.addEventListener(NetStatusEvent.NET_STATUS,statusHandler);
stream.addEventListener(IOErrorEvent.IO_ERROR,errorHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,metaHandler);
stream.bufferTime = model.config['bufferlength'];
stream.client = new NetClient(this);
video.attachNetStream(stream);
stream.soundTransform = transform;
stream.play(url);
//clearInterval(timeinterval);
//timeinterval = setInterval(timeHandler,100);
};
/** Receive NetStream status updates. **/
private function statusHandler(evt:NetStatusEvent):void {
if(evt.info.code == "NetConnection.Connect.Success") {
setStream();
} else if(evt.info.code == "NetConnection.Connect.Rejected" || evt.info.code == "NetConnection.Connect.Failed") {
connection.close();
if(stream) { stream.close(); }
video.attachNetStream(null);
model.sendEvent(ModelEvent.ERROR,{message:"Stream not found: "+ model.playlist[model.config['item']]['file']});
} else if(evt.info.code == "NetStream.Buffer.Full"){
if (model.config['state'] == ModelStates.BUFFERING) {
model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.PLAYING});
}
stream.bufferTime = 20
} else if(evt.info.code == "NetStream.Buffer.Empty"){
if(model.config['state'] != ModelStates.BUFFERING) {
model.sendEvent(ModelEvent.STATE,{newstate:ModelStates.BUFFERING});
}
if(completeFlag == true){
//ExternalInterface.call("playComplete");
completeFlag = false
}else{
stream.bufferTime=2
}
} else {
//model.sendEvent(ModelEvent.META,{info:evt.info.code});
}
};
/** Destroy the stream. **/
public function stop():void {
};
/** Set the volume level. **/
public function volume(vol:Number):void {
transform.volume = vol/100;
if(stream) {
stream.soundTransform = transform;
}
};
};
}
[最后编辑于 N神, at 2009-01-04 23:41:06]