简体   繁体   English

AMS没有收到取消发布命令SOMETIMES over rtmpt

[英]AMS doesn't receive unpublish command SOMETIMES over rtmpt

This one has had me going for a week at least. 这个让我至少走了一个星期。 I am trying to record a video file to AMS. 我正在尝试将视频文件录制到AMS。 It works great almost all of the time, except about 1 in 10 or 15 recording sessions, I never receive 'NetStream.Unpublish.Success' on my netstream from AMS when I close the stream. 它几乎在所有时间都很好用,除了大约十分之一或十五个记录会话,我在关闭流时从AMS上从未收到'NetStream.Unpublish.Success'。 I am connecting to AMS using rtmpt when this happens, it seems to work fine over rtmp. 当发生这种情况时,我使用rtmpt连接到AMS,它似乎比rtmp工作得更好。 Also, it seems like this only happens in safari on mac, but since its so intermittent I don't really trust that. 此外,似乎这只发生在Mac上的safari中,但由于它如此断断续续,我真的不相信。 Here is my basic flow: 这是我的基本流程:

// just a way to use promises with netStatusEvents
private function netListener(code:String, netObject:*):Promise {
    var deferred:Deferred = new Deferred();

    var netStatusHandler:Function = function (event:NetStatusEvent):void {
        if (event.info.level == 'error') {
            deferred.reject(event);
        } else if (event.info.code == code) {
            deferred.resolve(netObject);
            // we want this to be a one time listener since the connection can swap between record/playback
            netObject.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        }

    };

    netObject.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

    return deferred.promise;
}

// set up for recording
private function initRecord():void {

    Settings.recordFile = Settings.uniquePrefix + (new Date()).getTime();

    // detach any existing NetStream from the video
    _view.video.attachNetStream(null);

    // dispose of existing NetStream
    if (_videoStream) {
        _videoStream.dispose();
        _videoStream = null;
    }

    // disconnect before connecting anew
    (_nc.connected ? netListener('NetConnection.Connect.Closed', _nc) : Promise.when(_nc))
    .then(function (nc:NetConnection):void {

        netListener('NetConnection.Connect.Success', _nc)
        .then(function (nc:NetConnection):void {

            _view.video.attachCamera(_webcam);
            // get new NetStream
            _videoStream = getNetStream(_nc);

            ExternalInterface.call("CTplayer." + Settings.instanceName + ".onRecordReady", true);

        }, function(error:NetStatusEvent):void {
            ExternalInterface.call("CTplayer." + Settings.instanceName + ".onError", error.info);
        });

        _nc.connect(Settings.recordServer);

    }); // end ncClose

    if (_nc.connected) _nc.close();

}

// stop recording
private function stop():void {

    netListener('NetStream.Unpublish.Success', _videoStream)
    .then(function (ns:NetStream):void {        
        ExternalInterface.call("CTplayer." + Settings.instanceName + ".onRecordStop", Settings.recordFile);
    });

    _videoStream.attachCamera(null);
    _videoStream.attachAudio(null);
    _videoStream.close();
}

// start recording
private function record():void {

    netListener('NetStream.Publish.Start', _videoStream)
    .then(function (ns:NetStream):void {
        ExternalInterface.call("CTplayer." + Settings.instanceName + ".onRecording");
    });

    _videoStream.attachCamera(_webcam);
    _videoStream.attachAudio(_microphone);
    _videoStream.publish(Settings.recordFile, "record"); // fires NetStream.Publish.Success

}

Update I am now using a new NetConnection per connection attempt and also not forcing port 80 (see my 'answer' below). 更新我现在使用每个连接尝试新的NetConnection,也不强制端口80(参见下面的'回答')。 This has not solved my connection woes, only made the instances more infrequent. 这并没有解决我的连接问题,只是使实例更加罕见。 Now like every week or so I still have some random failure of ams or flash. 现在像每周左右我仍然有一些随机失败的AMS或闪光灯。 Most recently someone made a recording and then flash player was unable to load the video for playback. 最近有人制作了录音,然后flash播放器无法加载视频进行播放。 The ams logs show a connection attempt and then nothing. ams日志显示连接尝试,然后没有。 There should at least be a play event logged for when i load the metadata. 在加载元数据时,至少应该记录一个播放事件。 This is quite frustrating and impossible to debug. 这非常令人沮丧,无法调试。

I would try 2 distinct NetConnection objects, one for record and one for replay. 我会尝试2个不同的NetConnection对象,一个用于记录,一个用于重放。 This will remove your complexities around listeners adding/removing and connect/reconnect/disconnect logic and would IMO be cleaner. 这将消除围绕侦听器添加/删除和连接/重新连接/断开逻辑的复杂性,并且IMO会更清晰。 NetConnections are cheap, and I've always used one per task at hand. NetConnections很便宜,而且我每个任务总是使用一个。 The other advantage is that you can connect both at startup so the replay connection is ready instantly. 另一个优点是您可以在启动时连接两者,以便立即准备重播连接。

I've not seen a Promise used here before, but I'm not qualified to comment if that may cause a problem or not. 我以前没见过这里使用过的Promise,但如果可能导致问题,我没有资格发表评论。

I think my issue was connecting over port 80. I originally thought I had to use port 80 with rtmpt, so I set my Settings.recordServer variable to rtmpt://myamsserver.net:80/app . 我认为我的问题是通过端口80连接。我原本以为我必须使用端口80和rtmpt,所以我将我的Settings.recordServer变量Settings.recordServerrtmpt://myamsserver.net:80/app I'm now using a shotgun approach where I try a bunch of port/protocol combos at once and pick the first one to connect. 我现在正在使用霰弹枪方法,我一次尝试一堆端口/协议组合,并选择第一个连接。 It is almost always picking port 443 over rtmpt, which seems much faster and more stable all around than 80, and I haven't had this issue since. 它几乎总是选择端口443超过rtmpt,这似乎比80更快更稳定,我从那以后就没有这个问题了。 It could also be due to not reusing the same NetConnection object like Stefan suggested, its hard to say. 这也可能是由于没有像Stefan建议的那样重复使用相同的NetConnection对象,很难说。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM