接收NetGroup的流

时间:2013-08-31 17:38:06

标签: actionscript-3 flex p2p

我正在尝试接收NetGroup(电视)的流,但它在某些时候失败了。这是代码(简化为测试用例):

package lib
{
    import flash.events.NetStatusEvent;
    import flash.external.ExternalInterface;
    import flash.media.SoundTransform;
    import flash.media.Video;
    import flash.net.GroupSpecifier;
    import flash.net.NetConnection;
    import flash.net.NetGroup;
    import flash.net.NetStream;
    import flash.net.NetStreamPlayOptions;
    import mx.core.FlexGlobals;

    public class player
    {
        private var connection:NetConnection;
        private var group:NetGroup;
        private var group_option:GroupSpecifier;
        private var self:Object;
        private var stream:NetStream;
        private var stream_option:NetStreamPlayOptions;
        private var video:Video;

        private function _connect():void
        {
            self.connection = new NetConnection();
            self.connection.addEventListener(NetStatusEvent.NET_STATUS, self._event_net_status);
            self.connection.connect('rtmfp://p2p.peer-stream.com');
        }

        private function _event_net_status(event:NetStatusEvent):void
        {
            if(event.info.code === '')
                return;
            ExternalInterface.call('echo', 'status', event.info.code, false);
            switch(event.info.code)
            {
                case 'NetConnection.Connect.Success':
                    self._p2p_start();
                    break;
                case 'NetGroup.Connect.Success':
                    self._stream_init();
                    break;
                case 'NetStream.Connect.Success':
                    self._stream_start();
                    break;
            }
        }

        private function _p2p_start():void
        {
            self.group_option = new GroupSpecifier('G:0101010c0b0e70726f2073696562656e00');
            self.group_option.ipMulticastMemberUpdatesEnabled = true;
            self.group_option.multicastEnabled = true;
            self.group_option.objectReplicationEnabled = true;
            self.group_option.postingEnabled = true;
            self.group_option.routingEnabled = true;
            self.group_option.serverChannelEnabled = true;
            self.group = new NetGroup(self.connection, self.group_option.groupspecWithAuthorizations());
            self.group.addEventListener(NetStatusEvent.NET_STATUS, self._event_net_status);
        }

        private function _stream_init():void
        {
            self.stream = new NetStream(self.connection, self.group_option.groupspecWithAuthorizations());
            self.stream.addEventListener(NetStatusEvent.NET_STATUS, self._event_net_status);
        }

        private function _stream_start():void
        {
            self.video.attachNetStream(self.stream);
            self.stream.soundTransform = new SoundTransform();
            self.stream_option = new NetStreamPlayOptions();
            self.stream_option.streamName = 'G:0101010c0b0e70726f2073696562656e00';
            self.stream.play2(self.stream_option);
        }

        public function player():void
        {
            super();
            FlexGlobals.topLevelApplication.stage.quality = 'BEST';
            self = this;
            self.video = new Video(640, 480);
            FlexGlobals.topLevelApplication.video_box.addChild(self.video);
            self.video.smoothing = true;
            self._connect();
        }
    }
}

那里的ExternalInterface调用只显示了文本字段中传递的信息(我在浏览器中测试它)。以下是此输出的结果:

NetConnection.Connect.Success
NetGroup.Connect.Success
NetStream.Connect.Success
NetStream.Play.Reset
NetStream.Play.Start

但玩家没有任何反应。以下是我的想法:

  • 我使用与GroupSpecifier和streamName相同的字符串,但我认为这是错误的。如果是这样,我如何获得NetGroup的流名称?

  • 我正在启用GroupSpecifier中的所有内容,因为我不知道接收流的最低要求是什么,然后将其传递给其他客户端。也许让所有人在这里遇到麻烦。

也许有人可以告诉我如何解决这个问题才能最终看到一个流。

1 个答案:

答案 0 :(得分:0)

我能够解决问题:streamName确实是错误的,我可以手动找出正确的名称。我还必须将已知的组字符串直接传递给NetGroup和NetStream对象,而不是使用新的GroupSpecifier()。