Android QuickBlox视频调用扬声器不会自动打开



我已经在Android,iOS和Web中实现了QuickBlox。但是,在Android中,当我们收到视频通话时,我将面临一个问题,然后手机的扬声器不会自动打开。我想在接收视频通话时自动使用扬声器。

我的音频经理示例代码: -

audioManager = AppRTCAudioManager.create(this);
    isVideoCall = QBRTCTypes.QBConferenceType.QB_CONFERENCE_TYPE_VIDEO.equals(currentSession.getConferenceType());
    if (isVideoCall) {
        audioManager.setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE);

        Log.d(TAG, "AppRTCAudioManager.AudioDevice.SPEAKER_PHONE");
    } else {
        audioManager.setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.EARPIECE);
        audioManager.setManageSpeakerPhoneByProximity(SettingsUtil.isManageSpeakerPhoneByProximity(this));
        Log.d(TAG, "AppRTCAudioManager.AudioDevice.EARPIECE");
    }
    audioManager.setOnWiredHeadsetStateListener((plugged, hasMicrophone) -> {
        if (callStarted) {
            Toaster.shortToast("Headset " + (plugged ? "plugged" : "unplugged"));
        }
    });
    audioManager.setBluetoothAudioDeviceStateListener(connected -> {
        if (callStarted) {
            Toaster.shortToast("Bluetooth " + (connected ? "connected" : "disconnected"));
        }
    }); 

,当我尝试通过添加以下行来控制音频流管理器时,我的应用程序崩溃

   QBRTCAudioTrack localAudioTrack = currentSession.getMediaStreamManager().getLocalAudioTrack();
    localAudioTrack.setEnabled(true); // enable or disable audio stream

崩溃报告:

java.lang.RuntimeException: Unable to start activity ComponentInfo{.quickblox_videocalling.activities.CallActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.quickblox.videochat.webrtc.QBRTCAudioTrack com.quickblox.videochat.webrtc.QBMediaStreamManager.getLocalAudioTrack()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.quickblox.videochat.webrtc.QBRTCAudioTrack com.quickblox.videochat.webrtc.QBMediaStreamManager.getLocalAudioTrack()' on a null object reference
at com.ahgp.quickblox_videocalling.activities.CallActivity.initAudioManager(CallActivity.java:396)
at com.ahgp.quickblox_videocalling.activities.CallActivity.onCreate(CallActivity.java:192)
at android.app.Activity.performCreate(Activity.java:7183)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6944) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
2019-05-17 13:06:08.148 11514-11514/com.ahgp E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ahgp/com.ahgp.quickblox_videocalling.activities.CallActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.quickblox.videochat.webrtc.QBRTCAudioTrack com.quickblox.videochat.webrtc.QBMediaStreamManager.getLocalAudioTrack()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2957)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.quickblox.videochat.webrtc.QBRTCAudioTrack com.quickblox.videochat.webrtc.QBMediaStreamManager.getLocalAudioTrack()' on a null object reference
at com.ahgp.quickblox_videocalling.activities.CallActivity.initAudioManager(CallActivity.java:396)
at com.ahgp.quickblox_videocalling.activities.CallActivity.onCreate(CallActivity.java:192)
at android.app.Activity.performCreate(Activity.java:7183)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)

尝试以下代码

private AppRTCAudioManager audioManager;
audioManager = AppRTCAudioManager.create(this, new AppRTCAudioManager.OnAudioManagerStateListener() {
        @Override
        public void onAudioChangedState(AppRTCAudioManager.AudioDevice audioDevice) {
        }
    });

,而不是

audioManager.setDefaultAudioDevice(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE);

使用以下代码:

private AppRTCAudioManager appRTCAudioManager;
appRTCAudioManager = AppRTCAudioManager.create(this);

if (currentSessionExist() && currentSession.getConferenceType() == QBRTCTypes.QBConferenceType.QB_CONFERENCE_TYPE_AUDIO) {
 appRTCAudioManager.selectAudioDevice(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE);
}

和Onswitchaudio方法尝试以下方法:


 @Override
    public void onSwitchAudio() {      
       callService.switchAudio();
    }

public void switchAudio() {
        try {
            Log.v(TAG, "onSwitchAudio(), SelectedAudioDevice() = " + appRTCAudioManager.getSelectedAudioDevice());
            if (appRTCAudioManager.getSelectedAudioDevice() != AppRTCAudioManager.AudioDevice.SPEAKER_PHONE) {
                appRTCAudioManager.selectAudioDevice(AppRTCAudioManager.AudioDevice.SPEAKER_PHONE);
            } else {
                if (appRTCAudioManager.getAudioDevices().contains(AppRTCAudioManager.AudioDevice.BLUETOOTH)) {
                    appRTCAudioManager.selectAudioDevice(AppRTCAudioManager.AudioDevice.BLUETOOTH);
                } else if (appRTCAudioManager.getAudioDevices().contains(AppRTCAudioManager.AudioDevice.WIRED_HEADSET)) {
                    appRTCAudioManager.selectAudioDevice(AppRTCAudioManager.AudioDevice.WIRED_HEADSET);
                } else {
                    appRTCAudioManager.selectAudioDevice(AppRTCAudioManager.AudioDevice.EARPIECE);
                }
            }
        } catch (Exception e) {
            e.getMessage();
        }
    }

Note :将SDK更新到最新的SDK,有关更多详细信息,您可以检查官方链接

https://docs.quickblox.com/docs/android-video-calling-advanced

相关内容

  • 没有找到相关文章

最新更新