NetStream.play + video.attachNetStream不会显示任何视频
我是 Flash 编程新手。我想做的就是将本地网络摄像头传输到我的 red5 服务器并接收另一个视频中的数据。
因此,我编写了以下代码:
NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
client_nc = new NetConnection();
client_nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
client_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
client_nc.connect("rtmp://localhost/myApp/");
function netStatusHandler(e:NetStatusEvent):void
{
var code:String = e.info.code;
//log.info("code = " + code);
if (code == "NetConnection.Connect.Success")
{
cam_ns = new NetStream(client_nc);
cam_ns.attachCamera(camera);
cam_ns.attachAudio(mic);
cam_ns.publish("user_2", "live");
in_ns2 = new NetStream(client_nc);
in_ns2.play("user_2");
video2 = new Video(640, 480);
video2.attachNetStream(in_ns2);
//in_ns2.play("rtmp://localhost/myApp/user_2");
//in_ns2.play("user_2");
video2.x = 200;
video2.y = 10;
video2.width = 100;
video2.height = 100;
addChild(video2);
}
else
{
trace(code);
}
}
我在 1 个 NetConnections 上使用 2 个 NetStream,然后在第一个 NetConnections 上连接一个摄像头+麦克风。 之后,我播放此 NetStream 并尝试将此播放附加到第二个 Netstream 上并在新视频中播放。然而,这不起作用。
我对 as3 使用 flashdevelop,对 red5 服务器使用 eclipse。谁能帮助我吗?
I am new to Flash programming. All I wanted to do is stream my local webcam to my red5 server and receive the data in another video.
Therefore I wrote the following code:
NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
client_nc = new NetConnection();
client_nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
client_nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
client_nc.connect("rtmp://localhost/myApp/");
function netStatusHandler(e:NetStatusEvent):void
{
var code:String = e.info.code;
//log.info("code = " + code);
if (code == "NetConnection.Connect.Success")
{
cam_ns = new NetStream(client_nc);
cam_ns.attachCamera(camera);
cam_ns.attachAudio(mic);
cam_ns.publish("user_2", "live");
in_ns2 = new NetStream(client_nc);
in_ns2.play("user_2");
video2 = new Video(640, 480);
video2.attachNetStream(in_ns2);
//in_ns2.play("rtmp://localhost/myApp/user_2");
//in_ns2.play("user_2");
video2.x = 200;
video2.y = 10;
video2.width = 100;
video2.height = 100;
addChild(video2);
}
else
{
trace(code);
}
}
I use 2 NetStreams on 1 NetConnections and then attach a cam+mic on the first.
After that I play this NetStream and try to attach this playback on the 2nd Netstream and play it in a new Video. However, this doesnt work.
I use flashdevelop for as3 and eclipse for the red5 server. Can anyone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,它的工作方式如下:
其中 nc 是我的单个全局 NetConnection,streamName 是 an
,uic 是一个 UIComponent,
我从按钮调用 viewStream 方法
,我也遇到了 VideoDisplay 问题。所以我用 UIComponent 做了,效果很好。
也许您遇到问题是因为您尝试在发布后直接 ns.play 。我认为您应该尝试使用按钮并在开始发布后稍等片刻。
for me it worked like this:
where nc is my single global NetConnection and streamName is an
and uic is an UIComponent
i called viewStream method from a button
I had problems with VideoDisplay, too. So I did it with UIComponent and it works well.
Maybe you got problems because you try to ns.play directly after publish. I think you should try it with a button and wait a second after starting the publish.