如果已经问过这个问题,请原谅我,我找不到我的案例的答案。
所以,我有一个带有语音和视频通话功能的 Android 应用程序。我为此使用了 webRTC。
我能够使语音和视频通话在 Activity 中完美运行,但现在我想在用户退出 CallActivity 并返回 ChatActivity 时保持通话运行(例如发送文件/链接/照片)。
我设法使语音通话在后台服务中完美运行,但视频通话无法按预期工作。
即使正在播放视频轨道中的音频,也不会显示远程视频。
这是我的后台服务代码:
@Override
public void onAddStream(MediaStream mediaStream) {
if (mediaStream.videoTracks.size() > Constants.ONE || mediaStream.audioTracks.size() > Constants.ONE) {
return;
}
//check for video track, means this is a video call
if (!isAudioCall && mediaStream.videoTracks.size() > Constants.ZERO) {
remoteVideoTrack = mediaStream.videoTracks.get(Constants.ZERO);
CallActivityNew.remoteVideoTrack = remoteVideoTrack;
try {
localAudioTrack.setEnabled(true);
//Now ask the UI to display the video track
sendOrderToActivity(Constants.START_REMOTE_VIDEO, null);
} catch (Exception ignored) {}
} else if (mediaStream.audioTracks.size() > Constants.ZERO) {
//Means this is a Voice call, only audio tracks available
remoteAudioTrack = mediaStream.audioTracks.get(Constants.ZERO);
try {
localAudioTrack.setEnabled(true);
remoteAudioTrack.setEnabled(true);
} catch (Exception ignored) {}
}
}
在我的 CallActivity 代码下方:
case Constants.START_REMOTE_VIDEO: {
if (remoteVideoView == null) {
remoteVideoView = findViewById(R.id.remote_gl_surface_view);
}
remoteVideoView.init(eglBaseContext, null);
remoteVideoView.setEnableHardwareScaler(true);
remoteVideoView.setMirror(true);
remoteVideoView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
remoteVideoView.setZOrderMediaOverlay(true);
//Apply video track to the Surface View in order to display it
remoteVideoTrack.addSink(remoteVideoView);
//now enable local video track
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
//now enable local video track
remoteVideoTrack.setEnabled(true);
}
}, Constants.TIME_THREE_HUNDRED_MILLIS);
setSpeakerphoneOn(false);
break;
}
我正在从 Service 向 Activity 发送订单,“case Constants.START_REMOTE_VIDEO”在收到 Service 的订单后工作。
我看不出问题出在哪里,为什么我只听到声音但远程视频无法开始显示!
预先感谢您的帮助。