下面是as3 flash中的一个基本代码位。一个使用rtmp-red5的简单视频流示例。但我似乎在连接流时遇到了问题。我正在使用与red5服务器演示安装相同的视频文件。(我已经通过正确运行验证了ofla的安装演示)我的输出跟踪记录为连接成功和视频文件的播放开始。但我无法获得它的元数据,也无法让它真正播放。
netStatusHandler NetConnection.Connect.Success
netStatusHandler NetStream.Play.Reset
netStatusHandler NetStream.Play.Start
在提供视频文件的路径方面,我缺少什么它们位于默认red5安装附带的同一演示示例文件夹中。
package
{
import flash.display.*;
import flash.events.*;
import flash.media.*;
import flash.net.*
public class NetConnectionExample extends MovieClip
{
private var videoURL:String = "rtmp://localhost/oflaDemo/streams";
private var connection:NetConnection;
private var stream:NetStream;
public function NetConnectionExample()
{
// constructor code
connection = new NetConnection();
connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
connection.connect(videoURL, true);
}
private function netStatusHandler(event:NetStatusEvent):void
{
trace("netStatusHandler",event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
connectStream();
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + videoURL);
break;
case "NetStream.Play.Start":
break;
}
}
private function securityErrorHandler(event:SecurityErrorEvent):void
{
trace("securityErrorHandler: " + event);
}
private function connectStream():void
{
stream = new NetStream(this.connection);
stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler)
stream.client = new CustomClient();
var video:Video = new Video();
video.attachNetStream(stream);
stream.play(videoURL+"avatar.flv");
addChild(video);
}
function asyncErrorHandler(event:AsyncErrorEvent):void {
// ignore AsyncErrorEvent events.
}
}
}
class CustomClient {
public function onMetaData(info:Object):void
{
trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
}
public function onCuePoint(info:Object):void
{
trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
}
}
编辑:相关的在本地Red5服务器上,我应该将FLV文件放在哪里进行流式传输?
这是一个路径问题。名为ofLDemo的应用程序的rtmp视频文件夹被命名为流。给出这样的路径
private var videoURL:String = "rtmp://localhost/oflaDemo";
并且在连接流之后直接获得文件名。工作
stream.play("avatar.flv");