帖子
帖子
用户
博客
课程
12下一页
返回列表 发新帖
显示全部楼层
14
帖子
0
勋章
156
Y币

[BUG] 怎么联系@AC模块工作室,agoraLive模块使用

[复制链接]
发表于 2019-2-28 13:16:39
agoraLive模块使用能不能给个例子,我们开发时出不来视频
<!DOCTYPE html>
<html>
<head>
        <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <style>
        .bttn {
            margin: 50px;
            padding: 10px;
        }
    </style>
</head>
<body>
    <div class="bttn">
                主播身份加入频道
    </div>
    <div class="bttn">
                        观众身份加入频道
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    var agoraLive = null;
    //通信模式
    var livemode = "liveBroadcasting";
    var rolemode = "";
    var channelId = "testmeetting";
    var userId = 0;
        apiready = function(){
                api.parseTapmode();        
        };
        //主动创建
    function fnjoinChannelActive() {
        rolemode = "BROADCASTER";
        userId = 133667858;
        agoraLive = api.require('agoraLive');
        init();
    }
    //被动接收
    function fnjoinChannelPassive() {
        rolemode = "AUDIENCE";
        userId = 452876319;
        agoraLive = api.require('agoraLive');
        init();
    }

    function init() {
        agoraLive.init({
            appId: '13d7a037e46947198a70dc699e3af453'                 // 填写自己的appId
        }, function(ret) {
            console.log('初始化:' + JSON.stringify(ret));
            setChannelProfile();
            userJoinedListener();
        })
    }

    function setChannelProfile() {
        agoraLive.setChannelProfile({
            profile: livemode
        }, function(ret) {
            if (ret.status) {
                console.log('设置频道通话模式:' + '设置成功');
                enableVideo();
            }
        });
    }

    function enableVideo() {
        agoraLive.enableVideo(function(ret) {
            console.log('开启视频模式:' + JSON.stringify(ret));
            if(api.systemType =='ios'){
                        agoraLive.setClientRole({
                            role: rolemode
                        }, function(ret) {
                            if (ret.status) {
                                console.log('设置观众或主播模式:' + JSON.stringify(ret));
                                setOpenVideo();
                            }
                        });
            }else{
                    setOpenVideo();
            }
        });
    }

    function setOpenVideo() {
        if (rolemode == "BROADCASTER") {
            initVideoRect(userId, 0, 0, 480, 320);
            console.log('--------------------------------------------');
            setTimeout("setupLocalVideo()", 2000)
        }else if (rolemode == "AUDIENCE") {
           // enableLocalVideo(false);
            muteLocalAudioStream(false);
            joinChannelByToken();
            initVideoRect(userId, 0, 0,80, 60);
            setTimeout("setupRemoteVideo()", 2000)
        }
    }

    function initVideoRect(userId, x, y, w, h) {
        agoraLive.initVideoRect({
            uid: userId,
            rect: {
                x: x,
                y: y,
                w: w,
                h: h
            },
            fixedOn: "agoravideo",
            fixed: true
        });
    }

    function setupLocalVideo() {
        agoraLive.setupLocalVideo({
            renderMode: 'RENDER_MODE_HIDDEN',
            uid: userId
        }, function(ret) {
            console.log('设置本地视频显示信息' + JSON.stringify(ret));
            startPreview();
        });
    }

    function startPreview() {
        agoraLive.startPreview(function(ret) {
            console.log('启动本地视频预览' + JSON.stringify(ret));
            joinChannelByToken();
        });
        agoraLive.enableVideo();
    }

    function stopPreview() {
        agoraLive.stopPreview(function(ret) {
            alert('停止本地视频预览' + JSON.stringify(ret));
        });
    }

    function setupRemoteVideo() {
        agoraLive.setupRemoteVideo({
            renderMode: 'RENDER_MODE_HIDDEN',
            uid: userId
        }, function(ret) {
            if (ret.status) {
                console.log("显示主播视频:"+JSON.stringify(ret));
            }
        });
    }

    function joinChannelByToken() {
        agoraLive.joinChannelByToken({
                channelToken: '',
            channelId: channelId,
            uid: userId
        }, function(ret, err) {
            if (ret.status) {
                console.log("加入频道成功:" + JSON.stringify(ret));
            } else {

            }
        });
    }

    function userJoinedListener() {
        agoraLive.userJoinedListener({
            enable: true
        }, function(ret) {
            console.log("加入频道监听:" + JSON.stringify(ret));
            remId = ret.uid;
        });
    }

    function muteLocalAudioStream(flag) {
        agoraLive.muteLocalAudioStream({
            muted: flag
        }, function(ret) {
            if (ret.status) {
                console.log("禁用本地音频");
            }
        });
    }

    function enableLocalVideo(flag) {
        agoraLive.enableLocalVideo({
            enabled: flag
        }, function(ret) {
          if (ret.status) {
              console.log("禁用本地视频");
          }
        });
    }
</script>
</html>

146
帖子
3
勋章
3684
Y币
代码运行无效果吗?
4
帖子
0
勋章
11
Y币
粉红顽皮新 发表于 2019-2-28 13:57
代码运行无效果吗?

代码运行都没有问题,但是一直是黑屏的
4
帖子
0
勋章
11
Y币
粉红顽皮新 发表于 2019-2-28 13:57
代码运行无效果吗?

大佬能给个示例吗
380
帖子
4
勋章
6
Y币
检查fixedOn参数
语音通了吗,双方说话能听到吗
4
帖子
0
勋章
11
Y币
技术支持-F 发表于 2019-3-5 11:30
检查fixedOn参数
语音通了吗,双方说话能听到吗

现在还没有双方啊,我是主播端,我开启后我手机还是黑屏的,按道理不应该能看到我这边的影像吗
380
帖子
4
勋章
6
Y币
魇骑士 发表于 2019-3-6 08:35
现在还没有双方啊,我是主播端,我开启后我手机还是黑屏的,按道理不应该能看到我这边的影像吗 ...

如果你的页面是openFrame打开的话,fixedOn的值可以写api.frameName
2
帖子
0
勋章
11
Y币
解决了吗?遇见相同问题,求帮助
老哥问题解决了没。。。同样的问题。我自己摄像头,对方摄像头都是黑屏
技术支持-F 发表于 2019-3-6 12:02
如果你的页面是openFrame打开的话,fixedOn的值可以写api.frameName

大佬。。开视频后。我自己的摄像头就黑屏了。好像是闪一下黑屏的。就像开启成功了,但接着黑屏了
12下一页
您需要登录后才可以回帖 登录

本版积分规则