如何使用FluorineFx从客户端发布音频流?

时间:2010-08-20 08:56:09

标签: c# flex streaming rtmp fluorinefx

我无法弄清楚如何在客户端上使用FluorineFx将音频流从客户端发布到服务器。我们希望通过已建立的NetConnection将记录的音频数据从客户端传输到流。 FluorineFx中有一个NetStream类,但它没有发布方法。 FluorineFx中的NetStream类只有play方法。但据我所知,这会在客户端上播放来自服务器的流。

发布未在FluorineFx中实现,还是我错过了什么?

3 个答案:

答案 0 :(得分:2)

查看http://www.fluorinefx.com/docs/fluorine/

参见实时消息下的发布流和订阅流

答案 1 :(得分:0)

不幸的是,这个功能似乎没有实现。

答案 2 :(得分:0)

最近,我也研究了氟化物的代码。奇怪的是,尽管文档提到了这一点,但为什么发布没有在代码中实现。

实际上,在其PlayEngine.cs中,有一个类似的实现PullAndPush(),它可以从FLV文件中提取数据并将其推送到远程。

所以,我在Netstream类中尝试了一些类似的代码,它几乎可以工作,可以将流推送到 rtmplite 服务器,并且可以通过 rtmplite

public void Publish(params object[] arguments)
        {
            ValidationUtils.ArgumentConditionTrue(arguments != null && arguments.Length > 0, "arguments", "At least the name of a file must be specified");
            ValidationUtils.ArgumentNotNullOrEmptyOrWhitespace(arguments[0] as string, "name");
            _name = arguments[0] as string;


            INetConnectionClient client = _connection.NetConnectionClient;
            RtmpConnection connection = _connection.NetConnectionClient.Connection as RtmpConnection;
            IPendingServiceCallback callback = new CreateStreamCallBack(this, connection, new PublishCallBack(this,_connection, _name));
            client.Call("createStream", callback);
        }

        public void AttachFile(string filepath)
        {

            FileProvider fileProvider = new FileProvider(this.Scope, new System.IO.FileInfo(filepath));
            _pullPushPipe.Subscribe(fileProvider, null);
            PullAndPush();
        }

        public void PullAndPush()
        {

            while(true)
            {
                var msg = _pullPushPipe.PullMessage();
                if (msg == null)
                {
                    // No more packets to send
                    Stop();
                    break;
                }
                else
                {
                    if (msg is RtmpMessage)
                    {
                        RtmpMessage rtmpMessage = (RtmpMessage)msg;
                        IRtmpEvent body = rtmpMessage.body;
                     //   SendMessage(rtmpMessage);
                        // Adjust timestamp when playing lists
                        //  EnsurePullAndPushRunning();
                        _pullPushPipe.PushMessage(msg);
                    }
                }
            }
        }

        class PublishCallBack : IPendingServiceCallback
        {
            NetConnection _connection;
            NetStream _stream;
            string _name;
            string _mode;

            public PublishCallBack(NetStream stream, NetConnection connection, string name, string mode = "live")
            {
                _connection = connection;
                _name = name;
                _mode = mode;
                _stream = stream;
            }

            public void ResultReceived(IPendingServiceCall call)
            {
                if ("createStream".Equals(call.ServiceMethodName))
                {
                    RtmpConnection connection = _connection.NetConnectionClient.Connection as RtmpConnection;
                    object[] args = new object[2] {_name, _mode};
                    PendingCall pendingCall = new PendingCall("publish", args);
                    pendingCall.RegisterCallback(new PublishResultCallBack());
                    connection.Invoke(pendingCall, (byte)connection.GetChannelForStreamId(_stream.StreamId));
                }
            }
        }