在Android中使用WebRTC QuickBlox进行视频通话时,远程QBGLvideoView无法正常工作

时间:2015-07-24 04:35:23

标签: android quickblox

我正在使用Android中的WebRTC处理QuickBlox。我已经按照教程here进行了操作。我可以从一台设备拨打另一台设备,即当我从设备A拨打设备B时,我可以在local QBGLVideoView中看到我的视频,但我无法看到其他人的视频remote QBGLVideoView。设备B上也会出现同样的情况。任何人都可以告诉我哪里出错了。我的完整代码如下:

public class MainActivity extends ActionBarActivity implements OnClickListener,
    QBRTCClientSessionCallbacks, QBRTCClientConnectionCallbacks,
    QBRTCClientVideoTracksCallbacks {
Button sign_up, btn_login, btn_call, btn_recieve, btn_login2;
QBChatService chatService;
final QBUser user1 = new QBUser("temp151", "123456789");
final QBUser user2 = new QBUser("temp152", "123456789");

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    QBSettings.getInstance().fastConfigInit("xxxxxx", "xxxxxxxxxxxxxx",
            "xxxxxxxxxxxxxxx");

    sign_up = (Button) findViewById(R.id.sign_up);
    btn_login = (Button) findViewById(R.id.btn_login);
    btn_call = (Button) findViewById(R.id.btn_call);
    btn_recieve = (Button) findViewById(R.id.btn_recieve);
    btn_login2 = (Button) findViewById(R.id.btn_login2);
    sign_up.setOnClickListener(MainActivity.this);
    btn_login.setOnClickListener(MainActivity.this);
    btn_call.setOnClickListener(MainActivity.this);
    btn_recieve.setOnClickListener(MainActivity.this);
    btn_login2.setOnClickListener(MainActivity.this);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.sign_up:
        QBAuth.createSession(new QBEntityCallback<QBSession>() {

            @Override
            public void onError(List<String> arg0) {
                // TODO Auto-generated method stub
                Log.i("error", "" + arg0);
            }

            @Override
            public void onSuccess() {
                // TODO Auto-generated method stub

                user1.setFullName("temp151");
                user1.setPhone("123456789");

                QBUsers.signUp(user1, new QBEntityCallbackImpl<QBUser>() {
                    @Override
                    public void onSuccess(QBUser user, Bundle args) {

                    }

                    @Override
                    public void onError(List<String> errors) {

                    }
                });

            }

            @Override
            public void onSuccess(final QBSession session, Bundle arg1) {
                // TODO Auto-generated method stub
                final QBUser user1 = new QBUser("temp151", "123456789");

                user1.setFullName("temp151");
                user1.setPhone("123456789");

                QBUsers.signUp(user1, new QBEntityCallbackImpl<QBUser>() {
                    @Override
                    public void onSuccess(QBUser user, Bundle args) {
                        user1.setId(session.getUserId());
                        if (!QBChatService.isInitialized()) {
                            QBChatService.init(MainActivity.this);
                            chatService = QBChatService.getInstance();
                        }
                    }

                    @Override
                    public void onError(List<String> errors) {

                    }
                });
            }
        });

        break;
    case R.id.btn_login:
        create_session();
        break;
    case R.id.btn_call:

        QBRTCTypes.QBConferenceType qbConferenceType = QBConferenceType.QB_CONFERENCE_TYPE_VIDEO;
        List<Integer> opponents = new ArrayList<Integer>();
        opponents.add(4319012); // QBUser ID

        Map<String, String> userInfo = new HashMap<>();
        userInfo.put("user", "temp152");

        // Init session
        QBRTCSession session = QBRTCClient.getInstance()
                .createNewSessionWithOpponents(opponents, qbConferenceType);

        // Start call
        session.startCall(userInfo);

        break;
    case R.id.btn_recieve:

        // VideoChatConfig videoChatConfig =
        // QBVideoChatController.getInstance().callFriend(user2,
        // CallType.VIDEO_AUDIO, null);

        break;
    case R.id.btn_login2:

        QBAuth.createSession(user2, new QBEntityCallback<QBSession>() {

            @Override
            public void onError(List<String> arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onSuccess() {
                // TODO Auto-generated method stub

            }

            @Override
            public void onSuccess(QBSession arg0, Bundle arg1) {
                // TODO Auto-generated method stub
                user2.setId(arg0.getUserId());
                if (!QBChatService.isInitialized()) {
                    QBChatService.init(MainActivity.this);
                    chatService = QBChatService.getInstance();
                }
                chatService.login(user2,
                        new QBEntityCallbackImpl<QBUser>() {

                            @Override
                            public void onSuccess() {
                                // success
                                // Toast.makeText(getApplicationContext(),
                                // "Login successful" , 1000).show();
                                Log.e("Login Successful", "Logged In");

                                create_SignallingManager();
                            }

                            @Override
                            public void onError(List errors) {
                                // error
                                Log.i("errors", "" + errors.toString());
                            }
                        });
            }
        });

        break;
    default:
        break;
    }

}

public void create_SignallingManager() {
    // TODO Auto-generated method stub
    QBRTCClient.getInstance()
            .addSessionCallbacksListener(MainActivity.this);
    QBRTCClient.getInstance().addConnectionCallbacksListener(this);
    QBRTCClient.getInstance().addVideoTrackCallbacksListener(this);

    QBRTCClient.getInstance().prepareToProcessCalls(this);
    QBChatService
            .getInstance()
            .getVideoChatWebRTCSignalingManager()
            .addSignalingManagerListener(
                    new QBVideoChatSignalingManagerListener() {
                        @Override
                        public void signalingCreated(
                                QBSignaling qbSignaling,
                                boolean createdLocally) {
                            if (!createdLocally) {
                                QBRTCClient.getInstance().addSignaling(
                                        (QBWebRTCSignaling) qbSignaling);
                            } else {
                                QBRTCClient.getInstance().addSignaling(
                                        (QBWebRTCSignaling) qbSignaling);
                                try {

                                    QBVideoChatController
                                            .getInstance()
                                            .initQBVideoChatMessageListener();
                                } catch (XMPPException e) {
                                    e.printStackTrace();
                                }

                            }
                        }
                    });

    /*
     * SessionCallback loginlistener = new SessionCallback() {
     * 
     * @Override public void sessionCreated(InputMethodSession arg0) { //
     * TODO Auto-generated method stub try {
     * 
     * QBVideoChatController.getInstance()
     * .initQBVideoChatMessageListener(); } catch (XMPPException e) {
     * e.printStackTrace(); }
     * 
     * }
     * 
     * };
     */
}

public void create_session() {
    QBAuth.createSession(user1, new QBEntityCallback<QBSession>() {

        @Override
        public void onError(List<String> arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onSuccess() {
            // TODO Auto-generated method stub

        }

        @Override
        public void onSuccess(QBSession arg0, Bundle arg1) {
            // TODO Auto-generated method stub
            user1.setId(arg0.getUserId());
            if (!QBChatService.isInitialized()) {
                QBChatService.init(MainActivity.this);
                chatService = QBChatService.getInstance();
            }
            chatService.login(user1, new QBEntityCallbackImpl<QBUser>() {

                @Override
                public void onSuccess() {
                    // success
                    Log.i("Login Successful", "Logged In");
                    // Toast.makeText(getApplicationContext(),
                    // "Login successful" , 1000).show();

                    create_SignallingManager();

                }

                @Override
                public void onError(List errors) {
                    // error
                    Log.i("errors", "" + errors.toString());
                }
            });
        }
    });
}

@Override
public void onCallRejectByUser(QBRTCSession arg0, Integer arg1,
        Map<String, String> arg2) {
    // TODO Auto-generated method stub

}

@Override
public void onReceiveHangUpFromUser(QBRTCSession arg0, Integer arg1) {
    // TODO Auto-generated method stub
    // oast.makeText(MainActivity.this, "On hang up", 1000).show();
}

@Override
public void onReceiveNewSession(QBRTCSession arg0) {
    // TODO Auto-generated method stub
    Map<String, String> userInfo = arg0.getUserInfo();// new HashMap<String,
                                                        // String>();
    // userInfo.put("user", "temp152");

    // Toast.makeText(MainActivity.this, "OnReceive", 1000).show();
    // Accept incoming call
    arg0.acceptCall(userInfo);
    arg0.setVideoEnabled(true);

}

@Override
public void onSessionClosed(QBRTCSession arg0) {
    // QBRTCClient.getInstance().removeVideoTrackCallbacksListener(MainActivity.this);
    // TODO Auto-generated method stub

}

@Override
public void onSessionStartClose(QBRTCSession arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onUserNotAnswer(QBRTCSession arg0, Integer arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onConnectedToUser(QBRTCSession arg0, Integer arg1) {
    // TODO Auto-generated method stub
    Log.i("connected to second user", "connected");
}

@Override
public void onConnectionClosedForUser(QBRTCSession arg0, Integer arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onConnectionFailedWithUser(QBRTCSession arg0, Integer arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onDisconnectedFromUser(QBRTCSession arg0, Integer arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onDisconnectedTimeoutFromUser(QBRTCSession arg0, Integer arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onError(QBRTCSession arg0, QBRTCException arg1) {
    // TODO Auto-generated method stub
    Log.i("Error", "" + arg1.toString());

}

@Override
public void onStartConnectToUser(QBRTCSession arg0, Integer arg1) {
    // TODO Auto-generated method stub
    Log.i("Connection", "connecting to user");

}

@Override
public void onLocalVideoTrackReceive(QBRTCSession arg0, QBRTCVideoTrack arg1) {
    // TODO Auto-generated method stub
    QBGLVideoView localVideoVidew = (QBGLVideoView) findViewById(R.id.localVideoView);
    VideoRenderer localRenderer = new VideoRenderer(new VideoCallBacks(
            localVideoVidew, QBGLVideoView.Endpoint.LOCAL));
    arg1.addRenderer(localRenderer);
    localVideoVidew.setVideoTrack(arg1, QBGLVideoView.Endpoint.LOCAL);
}

@Override
public void onRemoteVideoTrackReceive(QBRTCSession arg0,
        QBRTCVideoTrack remoteVideoTrack, Integer arg2) {
    // TODO Auto-generated method stub

    // Toast.makeText(MainActivity.this, "Onremote", 1000).show();

    QBGLVideoView remoteVideoView = (QBGLVideoView) findViewById(R.id.remoteVideoView);
    VideoRenderer remoteRenderer = new VideoRenderer(new VideoCallBacks(
            remoteVideoView, QBGLVideoView.Endpoint.REMOTE));
    arg0.setVideoEnabled(true);
    arg0.setAudioEnabled(true);

    remoteVideoTrack.addRenderer(remoteRenderer);
    remoteVideoView.setVideoTrack(remoteVideoTrack,
            QBGLVideoView.Endpoint.REMOTE);

}

}

1 个答案:

答案 0 :(得分:0)

看起来一切正常。您是否检查了布局,因为您可以看到QBGLVideoView实例像往常一样工作View(GLSurfaceView)。也许,UI中的问题。 如果可以的话,请在对话中添加带有android日志的文件。