List of usage examples for android.media AudioManager MODE_IN_CALL
int MODE_IN_CALL
To view the source code for android.media AudioManager MODE_IN_CALL.
Click Source Link
From source file:Main.java
/** * Call checker/* w ww .j a v a 2s . c o m*/ * @param context * @return true if a call is going on. */ public static boolean isACallActive(Context context) { AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (manager.getMode() == AudioManager.MODE_IN_CALL) { return true; } else { return false; } }
From source file:org.zywx.wbpalmstar.plugin.uexaudio.EUExAudio.java
public static void onActivityDestroy(Context context) { BDebug.i(tag, "onActivityDestroy"); AudioManager audioManager = (AudioManager) context.getApplicationContext() .getSystemService(Context.AUDIO_SERVICE); if (audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION || audioManager.getMode() == AudioManager.MODE_IN_CALL) { audioManager.setMode(AudioManager.MODE_NORMAL); }// w w w. j a v a 2s . c om }
From source file:org.mitre.svmp.events.WebrtcHandler.java
public WebrtcHandler(BaseServer baseServer, VideoStreamInfo vidInfo, Context c) { base = baseServer;//w w w . ja v a 2s. c o m 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.example.rttytranslator.Dsp_service.java
public void startAudio() { if (!_enableDecoder) return;//from www. j a v a 2 s .c o m //boolean mic = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE); System.out.println("isRecording: " + isRecording); 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); } mRecorder.startRecording(); System.out.println("STARTING THREAD"); Thread ct = new captureThread(); ct.start(); } }
From source file:fr.inria.ucn.collectors.SysStateCollector.java
@SuppressWarnings("deprecation") private JSONObject getAudioState(Context c) throws JSONException { AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE); JSONObject data = new JSONObject(); data.put("is_bluetooth_a2dp_on", am.isBluetoothA2dpOn()); data.put("is_microphone_mute", am.isMicrophoneMute()); data.put("is_music_active", am.isMusicActive()); data.put("is_speaker_phone_on", am.isSpeakerphoneOn()); data.put("is_wired_headset_on", am.isWiredHeadsetOn()); switch (am.getMode()) { case AudioManager.MODE_IN_CALL: data.put("mode", "in_call"); break;/*from ww w . j a va 2 s .c om*/ case AudioManager.MODE_IN_COMMUNICATION: data.put("mode", "in_comm"); break; case AudioManager.MODE_NORMAL: data.put("mode", "normal"); break; case AudioManager.MODE_RINGTONE: data.put("mode", "ringtone"); break; case AudioManager.MODE_INVALID: default: data.put("mode", "invalid"); break; } switch (am.getRingerMode()) { case AudioManager.RINGER_MODE_VIBRATE: data.put("ringer_mode", "vibrate"); break; case AudioManager.RINGER_MODE_SILENT: data.put("ringer_mode", "silent"); break; case AudioManager.RINGER_MODE_NORMAL: data.put("ringer_mode", "normal"); break; default: data.put("ringer_mode", "invalid"); break; } return data; }
From source file:net.micode.soundrecorder.RecorderService.java
private void localStartRecording(int outputfileformat, String path, boolean highQuality, long maxFileSize) { if (mRecorder == null) { mRemainingTimeCalculator.reset(); if (maxFileSize != -1) { mRemainingTimeCalculator.setFileSizeLimit(new File(path), maxFileSize); }/*from w w w . jav a 2 s .c om*/ mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); if (outputfileformat == MediaRecorder.OutputFormat.THREE_GPP) { mRemainingTimeCalculator.setBitRate(SoundRecorder.BITRATE_3GPP); // mRecorder.setAudioChannels(1); mRecorder.setAudioSamplingRate(mAudioSampleRate); mRecorder.setAudioEncodingBitRate(SoundRecorder.BITRATE_3GPP); mRecorder.setOutputFormat(outputfileformat); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); } else if (outputfileformat == MediaRecorder.OutputFormat.AMR_NB) { mRemainingTimeCalculator.setBitRate(SoundRecorder.BITRATE_AMR); mRecorder.setAudioSamplingRate(highQuality ? 16000 : 8000); mRecorder.setOutputFormat(outputfileformat); mRecorder.setAudioEncoder( highQuality ? MediaRecorder.AudioEncoder.AMR_WB : MediaRecorder.AudioEncoder.AMR_NB); } else { mRemainingTimeCalculator.setBitRate(SoundRecorder.BITRATE_MP3); // mRecorder.setAudioChannels(1); mRecorder.setAudioSamplingRate(mAudioSampleRate); mRecorder.setAudioEncodingBitRate(SoundRecorder.BITRATE_MP3); mRecorder.setOutputFormat(outputfileformat); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); } mRecorder.setOutputFile(path); mRecorder.setOnErrorListener(this); // Handle IOException try { mRecorder.prepare(); } catch (IOException exception) { sendErrorBroadcast(Recorder.INTERNAL_ERROR); mRecorder.reset(); mRecorder.release(); mRecorder = null; return; } // Handle RuntimeException if the recording couldn't start try { mRecorder.start(); } catch (RuntimeException exception) { AudioManager audioMngr = (AudioManager) getSystemService(Context.AUDIO_SERVICE); boolean isInCall = (audioMngr.getMode() == AudioManager.MODE_IN_CALL); if (isInCall) { sendErrorBroadcast(Recorder.IN_CALL_RECORD_ERROR); } else { sendErrorBroadcast(Recorder.INTERNAL_ERROR); } mRecorder.reset(); mRecorder.release(); mRecorder = null; return; } mFilePath = path; mStartTime = System.currentTimeMillis(); mWakeLock.acquire(); mNeedUpdateRemainingTime = false; sendStateBroadcast(); showRecordingNotification(); NotificationManager nMgr = (NotificationManager) getApplicationContext() .getSystemService(NOTIFICATION_SERVICE); nMgr.cancel(notifyID); } }
From source file:com.brejza.matt.habmodem.Dsp_service.java
public void startAudio() { if (!_enableDecoder) return;// w ww.j a 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.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); }// w w w. j av a2 s . c o m enableEcho = true; }
From source file:de.azapps.mirakel.helper.TaskDialogHelpers.java
public static void playbackFile(final Activity context, final FileMirakel file, final boolean loud) { final MediaPlayer mPlayer = new MediaPlayer(); final AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (!loud) {//from ww w . ja v a 2 s. c om am.setSpeakerphoneOn(false); am.setMode(AudioManager.MODE_IN_CALL); context.setVolumeControlStream(AudioManager.STREAM_VOICE_CALL); } try { mPlayer.reset(); if (!loud) { mPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL); } mPlayer.setDataSource(file.getFileStream(context).getFD()); mPlayer.prepare(); mPlayer.start(); mPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(final MediaPlayer mp) { audio_playback_dialog.dismiss(); } }); am.setMode(AudioManager.MODE_NORMAL); audio_playback_playing = true; } catch (final IOException e) { Log.e(TAG, "prepare() failed"); } audio_playback_dialog = new AlertDialog.Builder(context).setTitle(R.string.audio_playback_title) .setPositiveButton(R.string.audio_playback_pause, null) .setNegativeButton(R.string.audio_playback_stop, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { mPlayer.release(); } }).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(final DialogInterface dialog) { mPlayer.release(); dialog.cancel(); } }).create(); audio_playback_dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(final DialogInterface dialog) { final Button button = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (audio_playback_playing) { button.setText(R.string.audio_playback_play); mPlayer.pause(); audio_playback_playing = false; } else { button.setText(R.string.audio_playback_pause); mPlayer.start(); audio_playback_playing = true; } } }); } }); audio_playback_dialog.show(); }
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); }/*from w ww . j a v a2 s . c o m*/ localStream.addTrack(peerConnectionFactory.createAudioTrack("ARDAMSa0", peerConnectionFactory.createAudioSource(new MediaConstraints()))); peerConnection.addStream(localStream); }