diff options
Diffstat (limited to 'examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java')
-rw-r--r-- | examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java b/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java index ad0e2d5..3ad26af 100644 --- a/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java +++ b/examples/android/src/org/appspot/apprtc/AppRTCDemoActivity.java @@ -34,7 +34,6 @@ import android.content.DialogInterface; import android.content.Intent; import android.content.pm.ActivityInfo; import android.graphics.Color; -import android.media.AudioManager; import android.net.Uri; import android.opengl.GLSurfaceView; import android.os.Bundle; @@ -72,6 +71,7 @@ public class AppRTCDemoActivity extends Activity private PeerConnectionClient pc; private AppRTCClient appRtcClient = new GAERTCClient(this, this); private AppRTCSignalingParameters appRtcParameters; + private AppRTCAudioManager audioManager = null; private View rootView; private View menuBar; private GLSurfaceView videoView; @@ -187,15 +187,9 @@ public class AppRTCDemoActivity extends Activity hudView.setVisibility(View.INVISIBLE); addContentView(hudView, hudLayout); - AudioManager audioManager = - ((AudioManager) getSystemService(AUDIO_SERVICE)); - // TODO(fischman): figure out how to do this Right(tm) and remove the - // suppression. - @SuppressWarnings("deprecation") - boolean isWiredHeadsetOn = audioManager.isWiredHeadsetOn(); - audioManager.setMode(isWiredHeadsetOn ? - AudioManager.MODE_IN_CALL : AudioManager.MODE_IN_COMMUNICATION); - audioManager.setSpeakerphoneOn(!isWiredHeadsetOn); + // Create and audio manager that will take care of audio routing, + // audio modes, audio device enumeration etc. + audioManager = AppRTCAudioManager.create(this); final Intent intent = getIntent(); Uri url = intent.getData(); @@ -253,6 +247,10 @@ public class AppRTCDemoActivity extends Activity @Override protected void onDestroy() { disconnect(); + if (audioManager != null) { + audioManager.close(); + audioManager = null; + } super.onDestroy(); } @@ -360,6 +358,12 @@ public class AppRTCDemoActivity extends Activity // All events are called from UI thread. @Override public void onConnectedToRoom(final AppRTCSignalingParameters params) { + if (audioManager != null) { + // Store existing audio settings and change audio mode to + // MODE_IN_COMMUNICATION for best possible VoIP performance. + logAndToast("Initializing the audio manager..."); + audioManager.init(); + } appRtcParameters = params; abortUnless(PeerConnectionFactory.initializeAndroidGlobals( this, true, true, VideoRendererGui.getEGLContext()), |