默默的Silverlight的调用时NETCONNECT失败闪光 [英] NetConnect fails silently in Flash when called from SilverLight

查看:177
本文介绍了默默的Silverlight的调用时NETCONNECT失败闪光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个复杂的问题,因为有很多的运动部件。我提前道歉。

This is a complex question, because there are a lot of moving parts. My apologies in advance.

我想写一个Silverlight控件承载一个Flash摄像头和麦克风(因为Silverlight不支持这些东西本身,更糟糕的运气)。我写了一个短小的Flex应用程序(WLocalWebCam.swf),该处理的摄像头,并且公开了两个外部方法:连接(URI:字符串,streamName中:字符串),和断开()。我可以通过JavaScript调用这些成功如下(简化,以消除错误处理,等等。):

I'm trying to write a Silverlight control that hosts a Flash camera and microphone (since Silverlight doesn't support these things natively, worse luck). I've written a short little Flex application ("WLocalWebCam.swf") which handles the camera, and exposes two external methods: connect(uri:String, streamName:String), and disconnect(). I can call these successfully through JavaScript as follows (simplified to remove error handling, etc.):

function connectWebCam(webCamID, rtmpUri, streamName) {
    var flashCam = getWebCam(webCamID);
    flashCam.Connect(rtmpUri, streamName);
}

function disconnectWebCam(webCamID) {
    var flashCam = getWebCam(webCamID);
    flashCam.Disconnect();
}

function getWebCam(id) {
    return document.getElementById(id);
}

当我调用这些函数从另一个JavaScript源(例如,一个按钮单击处理程序),网民正确连接到RTMP服务器(我使用Wowza)。然而,当我打电话从Silverlight的同一页面上完全相同,这些相同的功能,闪光灯相机不能连接到服务器RTMP

When I call these functions from another JavaScript source (e.g., a button click handler), the web cam connects correctly up to the RTMP server (I'm using Wowza). However, when I call exactly these same functions on the same page from Silverlight, the Flash camera fails to connect to the RTMP server.

/// <summary>
/// Connect() invokes the connectWebCam() JavaScript function contained in the WebCam.js file on the website.
/// The connectWebCam() method in turn calls the Connect() method on the contained Flash web cam object.
/// </summary>
public void Connect()
{
    ScriptObject connectWebCam = (ScriptObject)HtmlPage.Window.GetProperty("connectWebCam");
    connectWebCam.InvokeSelf(CameraID, RtmpUri.ToString(), CameraID);
}

然而,它不能在一个有趣的方式。 ActionScript的connect()方法被调用,它成功地调用的getConnection(),但handleNetStatus事件处理方法不会被调用,而Wowza服务器永远不会看到一个尝试连接。

However, it fails in an interesting fashion. The ActionScript connect() method gets called, it successfully calls getConnection(), but the handleNetStatus event handler method never gets called, and the Wowza server never sees an attempt to connect.

下面的动作脚本code我用,这次留在调试位。

Here's the ActionScript code I'm using, this time with the debugging bits left in.

public function connect(uri:String, name:String):void
{
    rtmpUri = uri;
    streamName = name;
    logMessage("Beginning attempt to open connection; rtmpUri=" + rtmpUri + "; streamName = " + streamName);
    logMessage("Retrieving camera.");
    cam = Camera.getCamera();
    if( cam != null )
    {
        logMessage("Retrieved camera.");
        cam.setMode( 320, 240, 20 );
        cam.setQuality( 0,0 );          
    }
    else
    {
        logMessage("Unable to retrieve camera instance.");
    }

    logMessage("Retrieving microphone.");
    mic = new Microphone();
    if (mic == null)
    {
        logMessage("Unable to retrieve microphone instance.");
    }
    logMessage("Retrieving NetConnection.");
    chatNC = getConnection(); 
}

private function getConnection(): NetConnection
{
    var nc: NetConnection = new NetConnection();    
    if (nc != null)
    {
        logMessage("Retrieved NetConnection().");
        nc.client = this;
        nc.objectEncoding = ObjectEncoding.AMF0;
        nc.addEventListener( NetStatusEvent.NET_STATUS, this.handleNetStatus );
        logMessage("Connecting to " + rtmpUri);
        nc.connect(rtmpUri); // <-- We get successfully to this point.
    }
    else
    {
        logMessage("Unable to retrieve new NetConnection()");
    }               
    return nc;
}

private function handleNetStatus( event:NetStatusEvent ):void
{
    logMessage("[SYSTEM MESSAGE] net status " + event.info.code + "  type " + event.type); // <-- We never get this far.  This bit never gets called.

    switch( event.info.code )
    {
        case "NetConnection.Connect.Success":
            publishVideoStream();
            break;
        default:
            Alert.show("Error connecting: " + event.info.code, "Error Connecting");
            break;
    }
}

这已经让我认真地抓我的头。

This has got me seriously scratching my head.

有谁知道为什么完全一样的动作会表现不同,如果称为Silverlight的与从JavaScript调用?在故障排除它有什么建议?

Does anyone know why the exact same ActionScript would behave differently if called from Silverlight vs. being called from JavaScript? Any suggestions on troubleshooting it?

推荐答案

叹息。没关系。原来它的确与众不同,如果你试图连接到 HTTP ://本地主机/视频聊天,而不是 RTMP:://本地主机/视频聊天。它所有的工作,当你给它正确的参数如预期。我必须看着那个codeA百倍之前,我发现我做错了什么。

Sigh. Never mind. Turns out it makes a difference if you try to connect to "http://localhost/videochat" instead of "rtmp:://localhost/videochat". It all works as expected when you give it the right parameters. I must have looked at that code a hundred times before I spotted what I did wrong.

这篇关于默默的Silverlight的调用时NETCONNECT失败闪光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆