List of usage examples for android.media AudioManager setMode
public void setMode(int mode)
From source file:org.mitre.svmp.events.WebrtcHandler.java
public WebrtcHandler(BaseServer baseServer, VideoStreamInfo vidInfo, Context c) { base = baseServer;/*from w ww . java 2 s . c om*/ context = c; // Pass in context to allow access to Android managed Audio driver. PeerConnectionFactory.initializeAndroidGlobals(context); // "Failed to initializeAndroidGlobals"); AudioManager audioManager = ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE)); boolean isWiredHeadsetOn = audioManager.isWiredHeadsetOn(); audioManager.setMode(isWiredHeadsetOn ? AudioManager.MODE_IN_CALL : AudioManager.MODE_IN_COMMUNICATION); audioManager.setSpeakerphoneOn(!isWiredHeadsetOn); sdpMediaConstraints = new MediaConstraints(); sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true")); sdpMediaConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true")); pcConstraints = constraintsFromJSON(vidInfo.getPcConstraints()); Log.d(TAG, "pcConstraints: " + pcConstraints); videoConstraints = constraintsFromJSON(vidInfo.getVideoConstraints()); Log.d(TAG, "videoConstraints: " + videoConstraints); // // videoConstraints = new MediaConstraints(); // videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minWidth","720")); // videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minHeight","1280")); // videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxWidth","720")); // videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("maxHeight","1280")); // videoConstraints.mandatory.add(new MediaConstraints.KeyValuePair("minFrameRate","24")); audioConstraints = new MediaConstraints(); //null; audioConstraints.mandatory.add(new MediaConstraints.KeyValuePair("audio", "true")); iceServers = iceServersFromPCConfigJSON(vidInfo.getIceServers()); onIceServers(iceServers); }
From source file:com.brejza.matt.habmodem.Dsp_service.java
public void disableEcho() { AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); manager.setMode(AudioManager.MODE_NORMAL); manager.setSpeakerphoneOn(false);//from w w w .j a v a2 s.c o m enableEcho = false; }
From source file:com.brejza.matt.habmodem.Dsp_service.java
public void enableEcho() { if (isRecording) { AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); manager.setMode(AudioManager.MODE_IN_CALL); manager.setSpeakerphoneOn(true); }/*from ww w .j a v a 2 s .c om*/ enableEcho = true; }
From source file:com.brejza.matt.habmodem.Dsp_service.java
public void startAudio() { if (!_enableDecoder) return;//from ww w . ja v a2 s .c om boolean mic = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE); System.out.println("isRecording: " + isRecording); logEvent("Starting Audio. Mic avaliable: " + mic, false); if (!isRecording) { isRecording = true; buffsize = AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT); buffsize = Math.max(buffsize, 3000); mRecorder = new AudioRecord(AudioSource.MIC, 8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, buffsize); mPlayer = new AudioTrack(AudioManager.STREAM_MUSIC, 8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, 2 * buffsize, AudioTrack.MODE_STREAM); if (enableEcho) { AudioManager manager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); manager.setMode(AudioManager.MODE_IN_CALL); manager.setSpeakerphoneOn(true); } if (mRecorder.getState() != AudioRecord.STATE_INITIALIZED) { mRecorder = new AudioRecord(AudioSource.DEFAULT, 8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, buffsize); if (mRecorder.getState() != AudioRecord.STATE_INITIALIZED) { logEvent("Error - Could not initialise audio", true); return; } logEvent("Using default audio source", false); } mRecorder.startRecording(); System.out.println("STARTING THREAD"); Thread ct = new captureThread(); logEvent("Starting Audio Thread.", false); setDecoderRunningNotification(); ct.start(); } }
From source file:com.digium.respokesdk.RespokeCall.java
private void addLocalStreams(Context context) { AudioManager audioManager = ((AudioManager) context.getSystemService(Context.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); localStream = peerConnectionFactory.createLocalMediaStream("ARDAMS"); if (!audioOnly) { VideoCapturer capturer = getVideoCapturer(); MediaConstraints videoConstraints = new MediaConstraints(); videoSource = peerConnectionFactory.createVideoSource(capturer, videoConstraints); VideoTrack videoTrack = peerConnectionFactory.createVideoTrack("ARDAMSv0", videoSource); videoTrack.addRenderer(new VideoRenderer(localRender)); localStream.addTrack(videoTrack); }/* ww w. j a va 2 s . co m*/ localStream.addTrack(peerConnectionFactory.createAudioTrack("ARDAMSa0", peerConnectionFactory.createAudioSource(new MediaConstraints()))); peerConnection.addStream(localStream); }
From source file:com.ferdi2005.secondgram.voip.VoIPService.java
private void configureDeviceForCall() { needPlayEndSound = true;//from w w w .j a v a 2 s . c o m AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); am.setMode(AudioManager.MODE_IN_COMMUNICATION); am.setSpeakerphoneOn(false); am.requestAudioFocus(this, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN); SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE); Sensor proximity = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY); try { if (proximity != null) { proximityWakelock = ((PowerManager) getSystemService(Context.POWER_SERVICE)) .newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "telegram-voip-prx"); sm.registerListener(this, proximity, SensorManager.SENSOR_DELAY_NORMAL); } } catch (Exception x) { FileLog.e("Error initializing proximity sensor", x); } }
From source file:com.ferdi2005.secondgram.voip.VoIPService.java
@Override public void onDestroy() { FileLog.d("=============== VoIPService STOPPING ==============="); stopForeground(true);//from w ww .j a v a2 s . c o m stopRinging(); NotificationCenter.getInstance().removeObserver(this, NotificationCenter.appDidLogout); SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE); Sensor proximity = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY); if (proximity != null) { sm.unregisterListener(this); } if (proximityWakelock != null && proximityWakelock.isHeld()) { proximityWakelock.release(); } unregisterReceiver(receiver); if (timeoutRunnable != null) { AndroidUtilities.cancelRunOnUIThread(timeoutRunnable); timeoutRunnable = null; } super.onDestroy(); sharedInstance = null; AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { NotificationCenter.getInstance().postNotificationName(NotificationCenter.didEndedCall); } }); if (controller != null && controllerStarted) { lastKnownDuration = controller.getCallDuration(); updateStats(); StatsController.getInstance().incrementTotalCallsTime(getStatsNetworkType(), (int) (lastKnownDuration / 1000) % 5); if (needSendDebugLog) { String debugLog = controller.getDebugLog(); TLRPC.TL_phone_saveCallDebug req = new TLRPC.TL_phone_saveCallDebug(); req.debug = new TLRPC.TL_dataJSON(); req.debug.data = debugLog; req.peer = new TLRPC.TL_inputPhoneCall(); req.peer.access_hash = call.access_hash; req.peer.id = call.id; ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) { FileLog.d("Sent debug logs, response=" + response); } }); } controller.release(); controller = null; } cpuWakelock.release(); AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); if (isBtHeadsetConnected && !playingSound) am.stopBluetoothSco(); am.setMode(AudioManager.MODE_NORMAL); am.unregisterMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class)); if (haveAudioFocus) am.abandonAudioFocus(this); if (!playingSound) soundPool.release(); ConnectionsManager.getInstance().setAppPaused(true, false); }