实现纯语音互动
在开始通话时,音视频通话 UIKit 默认打开摄像头和麦克风,并将扬声器作为音频输出设备。
如需更改此默认配置,例如在开始通话时关闭摄像头,或者不使用扬声器(如果不使用扬声器,则将使用系统的默认音频输出设备,如听筒、耳机、蓝牙等),您可以修改以下配置:
turnOnCameraWhenJoining
:通话开始时是否打开摄像头。true:打开(默认)。false:关闭。turnOnMicrophoneWhenJoining
:通话开始时是否打开麦克风。true:打开(默认)。false:关闭。useSpeakerWhenJoining
:通话开始时是否使用扬声器。true:使用扬声器(默认)。false:使用系统的默认音频输出设备,如听筒、耳机、蓝牙等。
以下是参考代码:
基本通话
携带邀请的通话
public class CallActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_call);
long appID = YourAppID;
String appSign = YourAppSign;
String userID = "userID";
String userName = "userName";
String callID = "testCallID";
// Modify your custom configurations here.
ZegoUIKitPrebuiltCallConfig config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall();
config.turnOnCameraWhenJoining = false;
config.turnOnMicrophoneWhenJoining = false;
config.useSpeakerWhenJoining = true;
ZegoUIKitPrebuiltCallFragment fragment = ZegoUIKitPrebuiltCallFragment
.newInstance(appID, appSign, callID, userID, userName, config);
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, fragment)
.commitNow();
}
}
1
public class MainActivity extends AppCompatActivity {
long appID = YourAppID;
String appSign = YourAppSign;
String userID = "userID";
String userName = "userName";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initCallInviteService();
}
public void initCallInviteService() {
ZegoUIKitPrebuiltCallInvitationConfig callInvitationConfig = new ZegoUIKitPrebuiltCallInvitationConfig(),
callInvitationConfig.provider = new ZegoUIKitPrebuiltCallConfigProvider() {
@Override
public ZegoUIKitPrebuiltCallConfig requireConfig(ZegoCallInvitationData invitationData) {
ZegoUIKitPrebuiltCallConfig config;
boolean isVideoCall = invitationData.type == ZegoInvitationType.VIDEO_CALL.getValue();
boolean isGroupCall = invitationData.invitees.size() > 1;
if (isVideoCall && isGroupCall) {
config = ZegoUIKitPrebuiltCallConfig.groupVideoCall();
} else if (!isVideoCall && isGroupCall) {
config = ZegoUIKitPrebuiltCallConfig.groupVoiceCall();
} else if (!isVideoCall) {
config = ZegoUIKitPrebuiltCallConfig.oneOnOneVoiceCall();
} else {
config = ZegoUIKitPrebuiltCallConfig.oneOnOneVideoCall();
}
// Modify your custom calling configurations here.
config.turnOnCameraWhenJoining = false;
config.turnOnMicrophoneWhenJoining = false;
config.useSpeakerWhenJoining = true;
return config;
}
);
ZegoUIKitPrebuiltCallService.init(getApplication(), appID, appSign, userID, userName,
callInvitationConfig);
}
@Override
protected void onDestroy() {
super.onDestroy();
ZegoUIKitPrebuiltCallService.logout();
}
}
1