Sinch视频聊天,无法显示远程视频

Posted

技术标签:

【中文标题】Sinch视频聊天,无法显示远程视频【英文标题】:Sinch video chat , cannot get remote video displayed 【发布时间】:2016-09-14 11:44:09 【问题描述】:

我目前正在尝试 android Sinch SDK,所以我目前正在开发一个测试应用程序来尝试一些功能。我成功地进行了语音应用程序到应用程序呼叫,但是在尝试视频应用程序到应用程序呼叫时遇到问题:建立连接后,呼叫者可以显示远程视频,但接收者无法显示远程视频(两者都可以显示他们的本地视频)。 这是我的代码:

来电监听器

public class SinchVidListner implements VideoCallListener 
    private Activity a ;
    private TextView callState ;
    private Button dec ;
    private LinearLayout gl ;


    public SinchVidListner(Activity act)
    
        a=act;
        callState = (TextView) a.findViewById(R.id.fullscreen_content);
        dec=(Button) a.findViewById(R.id.Decline) ;

    
    @Override
    public void onVideoTrackAdded(Call call) 

        //remoteView = vc.getRemoteView();
    

    @Override
    public void onCallProgressing(Call call) 
        callState.setText("Ringing");
    

    @Override
    public void onCallEstablished(Call call) 
        DataHolder.getInstance().stop();
        a.setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
        callState.setText("");
        dec.setVisibility(View.GONE);
        if (! DataHolder.getInstance().isVidadd())
        VideoController vc = DataHolder.getInstance().getClient().getVideoController();
         gl= (LinearLayout) a.findViewById(R.id.trust) ;
            gl.removeAllViews();
            gl.addView(vc.getLocalView());
            DataHolder.getInstance().setVidadd(true);
    

    @Override
    public void onCallEnded(Call call) 
        DataHolder.getInstance().setCall(null);
        Button button = (Button) a.findViewById(R.id.call) ;
        button.setText("Call");
        a.setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
        gl.removeAllViews();
        callState.setText("Call ended");
        DataHolder.getInstance().stop();
        dec.setVisibility(View.GONE);

    

    @Override
    public void onShouldSendPushNotification(Call call, List<PushPair> list) 

    

来电监听器

public class SinchCallClientListener implements CallClientListener 
    Activity a ;
    Call call ;
    public SinchCallClientListener(Activity activity) 
        a=activity ;
    

    @Override
    public void onIncomingCall(CallClient callClient, Call incomingCall) 
        Button button = (Button) a.findViewById(R.id.call) ;
        //call = incomingCall;
        //call.answer();
        if (! incomingCall.getDetails().isVideoOffered())
        incomingCall.addCallListener(new SinchCallListener(a));
        else
        
            DataHolder.getInstance().setVidadd(false);
            incomingCall.addCallListener(new SinchVidListner(a));
        
        DataHolder.getInstance().setCall(incomingCall);
        TextView callState = (TextView) a.findViewById(R.id.fullscreen_content);
        callState.setText("Ringing");
        button.setText("Answer");
        Button dec = (Button) a.findViewById(R.id.Decline) ;
        dec.setVisibility(View.VISIBLE);
        DataHolder.getInstance().play();

    

通话/挂断/接听实现

public void makecall(View v)
   //DataHolder.getInstance().getCall().addCallListener(new SinchCallListener(this));
        int type = DataHolder.getInstance().getType();
       call=DataHolder.getInstance().getCall() ;
       if (call == null) //make a call
           if (type==R.id.next) //when it's a just voice call
           call=sinchClient.getCallClient().callUser(recipientId) ;
           call.addCallListener(new SinchCallListener(this));
           else //when it's a Video call
           
               call=sinchClient.getCallClient().callUserVideo(recipientId) ;
               DataHolder.getInstance().setClient(sinchClient);
               call.addCallListener(new SinchVidListner(this));

           
           DataHolder.getInstance().setCall(call);
           button.setText("Hang Up");

        else if (button.getText()=="Hang Up") //hangup
           call.hangup();
           call=null ;
           DataHolder.getInstance().setCall(call) ;
           button.setText("Call");
       
       else  //answer
           DataHolder.getInstance().stop();
           call.answer();
           if (type==R.id.next) //when it's a just voice call
           call.addCallListener(new SinchCallListener(this));
           else // it's video call
              DataHolder.getInstance().setClient(sinchClient);
               call.addCallListener(new SinchVidListner(this));
           button.setText("Hang Up");
       
   

请随时要求我进一步澄清,谢谢。

【问题讨论】:

【参考方案1】:

您需要在添加的视频轨道上添加远程视频

  @Override
public void onVideoTrackAdded(Call call) 
    // Get a reference to your SinchClient, in the samples this is done through the service interface:
    VideoController vc = getSinchServiceInterface().getVideoController();
    View myPreview = vc.getLocalView();
    View remoteView = vc.getRemoteView();
    // Add the views to your view hierarchy
    ...

【讨论】:

我在线性布局中添加远程视图以显示远程视图,但它显示黑屏,没有其他任何帮助? @cjensen 找到解决方案了吗?

以上是关于Sinch视频聊天,无法显示远程视频的主要内容,如果未能解决你的问题,请参考以下文章

Sinch 视频通话示例问题

Sinch 视频应用程序问题

如何在 Sinch 中禁用视频

Sinch 暂停传出的音频或视频

Sinch Video 通话声音来自前置扬声器

WebRTC 无法在控制台上的 RTCPeerConnection 错误上执行“addIceCandidate”,但仍可以显示远程和本地视频