【问题标题】:OpenTok Api Broadcasted video placement in web pageOpenTok Api 在网页中广播视频放置
【发布时间】:2013-05-19 09:01:31
【问题描述】:

我正在使用 opentok 并连接到广播服务并在页面底部获取 Flash Player 的对象。

我怎样才能把它放在一个特定的 div..

这是我用来连接 opentol API 的代码

function initiatecall() {
            if (session != undefined) {
                if (!iscalled) {
                    session.addEventListener("sessionConnected", sessionConnectedHandler);
                    session.addEventListener("streamCreated", streamCreatedHandler);
                    session.connect("21457612", token_id); // Replace with your API key and token. See https://dashboard.tokbox.com/projects
                    // and https://dashboard.tokbox.com/projects
                    iscalled = true;

                    $.ajax({
                        data: '{"ChatId":"' + chat_id + '","NurseId":"' + nurse_id + '","DeviceType":"Browser"}',
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json;charset=utf-8",
                        url: "someurl.asmx/MakeCall",
                        success: function (data) { initiatecall(chat_id, session_id, token_id); },
                        eror: function (a, b, c) { alert(a.responseText); }
                    });

                }
            } else {
                alert("Session Expired!!");
            }
        }

        function sessionConnectedHandler(event) {
            subscribeToStreams(event.streams);
            session.publish();
        }

        function streamCreatedHandler(event) {
            subscribeToStreams(event.streams);
        }

        function subscribeToStreams(streams) {
            for (i = 0; i < streams.length; i++) {
                var stream = streams[i];
                if (stream.connection.connectionId != session.connection.connectionId) {
                    session.subscribe(stream);
                }
            }
        }

        function exceptionHandler(event) {
            alert("Exception: " + event.code + "::" + event.message);
        }


        </script>
    <!--End of code-->
    <!--Signal R-->
    <script type="text/javascript">
        $(function () {

            //$.hubConnection.app.MapHubs(new HubConfiguration { EnableCrossDomain = true });
            // Proxy created on the fly
            var chat = $.connection.chat
            //var chat = $.connection.WebPushNotification;
            //alert(chat);
            // Start the connection
            //            $.connection.hub.start();
            //port 1935
            $.connection.hub.start({ transport: 'auto' }, function () {
                //alert('connected');
                $("#info").append("<br/>Hub Started..");
                initiatecall();
                $("#info").append("<br/>Call Initiated..");
                chat.send(chat_id + ',' + session_id + ',' + token_id + ',' + '<%=Session["UserId"].ToString() %>');
                $("#info").append("<br/>Broadcasted Message..");
                //$('#MainContent_connected').text('Connected to chat room');
            });

            // Declare a function on the chat hub so the server can invoke it
            chat.addMessage = function (message) {
                //alert(message);
                //$('#messages').append('<li>' + message + '</li>');
            };
        });

    </script>

我已经采取了一个 div 来显示所有的进度。

 <div id="info">
        </div>

它将我连接到我的视频并请求许可,但它占据了自己的位置,而不是根据我的设计。

【问题讨论】:

    标签: javascript jquery .net ajax opentok


    【解决方案1】:

    我认为您应该添加参数replaceElementId 并将其值设置为应该替换为播放器的div id。 示例:如果要在#container div 中加载播放器,则在#container 中定义一个div #replaceElementId,它将被播放器替换:

    <div id="container">
      <div id="replaceElementId"></div>
    </div>
    

    【讨论】:

    • 已经试过了,但是播放器总是显示在底部。
    • 如果我能看看你的场景会很有帮助。你能把你的代码放到网上吗?
    【解决方案2】:

    您必须包含将在您的 DOM 中替换的元素的 ID(例如 replaceElementId

    <div id="container">
       <div id="replaceElementId"></div>
    </div>
    

    修改您的session.subscribe

    function subscribeToStreams(streams) {
        for (i = 0; i < streams.length; i++) {
            var stream = streams[i];
            if (stream.connection.connectionId != session.connection.connectionId) {
                //This is where you have to make changes
                //session.subscribe(stream);
    
                  session.subscribe(stream, "replaceElementId", 
                      { width:640, height:480 } );
            }
        }
    }
    

    如您所见,您甚至可以定义自己的视频流大小或其他 GUI 更改。

    更多信息见官方文档TokBox API:Session

    【讨论】:

      猜你喜欢
      • 2021-06-20
      • 2014-07-16
      • 2014-07-31
      • 2016-09-23
      • 1970-01-01
      • 2021-08-21
      • 2013-12-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多