Example usage for android.media AudioManager setMode

List of usage examples for android.media AudioManager setMode

Introduction

In this page you can find the example usage for android.media AudioManager setMode.

Prototype

public void setMode(int mode) 

Source Link

Document

Sets the audio mode.

Usage

From source file:Main.java

public static void openSpeaker(Context context, boolean on) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (on) {// w  ww.ja  va2  s . co m
        audioManager.setMode(AudioManager.MODE_NORMAL);
        audioManager.setSpeakerphoneOn(true);
    } else {
        audioManager.setSpeakerphoneOn(false);
    }
}

From source file:Main.java

public static void restoreSystemAudioSetting(Context context) {
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (audioManager != null) {
        audioManager.setSpeakerphoneOn(false);
        audioManager.setMode(AudioManager.MODE_NORMAL);
    }//w w w  .  j a v a 2 s.  c om

}

From source file:Main.java

public static void setCurrentVolume(int percent, Context mc) {
    AudioManager am = (AudioManager) mc.getSystemService(Context.AUDIO_SERVICE);
    int maxvolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    am.setStreamVolume(AudioManager.STREAM_MUSIC, (maxvolume * percent) / 100,
            AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
    am.setMode(AudioManager.MODE_INVALID);
}

From source file:org.linphone.compatibility.ApiElevenPlus.java

public static void setAudioManagerInCallMode(AudioManager manager) {
    if (manager.getMode() == AudioManager.MODE_IN_COMMUNICATION) {
        Log.w("---AudioManager: already in MODE_IN_COMMUNICATION, skipping...");
        return;//from   w w  w .  jav a 2 s .  c  o  m
    }
    Log.d("---AudioManager: set mode to MODE_IN_COMMUNICATION");
    manager.setMode(AudioManager.MODE_IN_COMMUNICATION);
}

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  ww.  jav a  2s  . c  om
}

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 .  jav a2  s.  c  o  m
        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.loloof64.android.capturing_audio.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    recordingButton = (ImageButton) findViewById(R.id.button_recording);
    timerTextView = (TextView) findViewById(R.id.timer_text_view);

    AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_NORMAL);

    FragmentManager fragmentManager = getSupportFragmentManager();
    recorderFragment = (RecorderFragment) fragmentManager.findFragmentByTag(RECORDER_FRAGMENT_TAG);

    SimpleTimer.setTimerListener(this);

    if (recorderFragment == null) {
        recorderFragment = new RecorderFragment();
        recorderFragment.setFileRenamingManager(this);
        recorderFragment.setRecordingStatusListener(this);
        fragmentManager.beginTransaction().add(recorderFragment, RECORDER_FRAGMENT_TAG).commit();
    }//from   ww w .  j a  va 2 s .  c  o m

    processStatusChange(recorderFragment.isInRecordingStatus());
}

From source file:com.example.rttytranslator.Dsp_service.java

public void startAudio() {
    if (!_enableDecoder)
        return;/*  ww w .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:gstb.fd.eofficial.oa.im.widget.chatrow.EaseChatRowVoicePlayClickListener.java

public void playVoice(String filePath) {
    Log.e("sssssss", "sssssssssssssss");
    if (!(new File(filePath).exists())) {
        return;//from   w w  w  . j av  a2 s  . c om
    }
    //      playMsgId = message.getMsgId();
    AudioManager audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);

    mediaPlayer = new MediaPlayer();
    //      if (EaseUI.getInstance().getSettingsProvider().isSpeakerOpened()) {
    audioManager.setMode(AudioManager.MODE_NORMAL);
    audioManager.setSpeakerphoneOn(true);
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
    //      } else {
    //         audioManager.setSpeakerphoneOn(false);// 
    // ?Earpiece???
    //         audioManager.setMode(AudioManager.MODE_IN_CALL);
    //         mediaPlayer.setAudioStreamType(AudioManager.STREAM_VOICE_CALL);
    //      }
    try {
        mediaPlayer.setDataSource(filePath);
        mediaPlayer.prepare();
        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                // TODO Auto-generated method stub
                mediaPlayer.release();
                mediaPlayer = null;
                stopPlayVoice(); // stop animation
            }

        });
        isPlaying = true;
        currentPlayListener = this;
        mediaPlayer.start();
        showAnimation();

        // ?
        if (message.direct() == EMMessage.Direct.RECEIVE) {

            //             if (!message.isAcked() && chatType == EMMessage.ChatType.Chat) {
            //                       // ??
            ////                     EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
            //             }
            if (!message.isListened() && iv_read_status != null
                    && iv_read_status.getVisibility() == View.VISIBLE) {
                // ????
                iv_read_status.setVisibility(View.INVISIBLE);
                message.setListened(true);
                MessageDao.instance(activity).updateListen(message.getMsgId());
                //               EMClient.getInstance().chatManager().setMessageListened(message);
            }

        }

    } catch (Exception e) {
        System.out.println();
    }
}

From source file:com.mindprotectionkit.freephone.RedPhoneService.java

private void shutdownAudio() {
    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    am.setMode(AudioManager.MODE_NORMAL);
}