Java Code Examples for android.media.AudioManager#MODE_NORMAL

The following examples show how to use android.media.AudioManager#MODE_NORMAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RtcActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
 * 免提,切换外放和听筒
 */
private void switchAudioMute() {
    int result = audioManager.ting();
    if(result == AudioManager.MODE_NORMAL) {
        if(videoEnable) {
            rtcMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_open), null, null);
        } else {
            audioMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_open), null, null);
        }
    } else if(result == AudioManager.MODE_IN_COMMUNICATION) {
        if(videoEnable) {
            rtcMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_close), null, null);
        } else {
            audioMute.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(R.drawable.pub_imsdk_rtc_audio_close), null, null);
        }
    }

}
 
Example 2
Source File: AssistantService.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(AudioManager audioManager) {
    if (voiceMediator.isBlueToothHeadSet()) {
        if (!voiceMediator.isSuportA2DP()) {
            if (audioManager.getMode() != AudioManager.MODE_NORMAL) {
                Log.e(TAG, "playInChannel>>setMode(AudioManager.MODE_NORMAL)");
                audioManager.setMode(AudioManager.MODE_NORMAL);
            }
            if (audioManager.isBluetoothScoOn()) {
                audioManager.setBluetoothScoOn(false);
                audioManager.stopBluetoothSco();
            }
        } else {
            if (!audioManager.isBluetoothA2dpOn()) {
                Log.e(TAG, "playInChannel>>setBluetoothA2dpOn(true)");
                audioManager.setBluetoothA2dpOn(true);
            }
        }
    }
}
 
Example 3
Source File: MediaManager.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
private int getAudioTargetMode() {
	int targetMode = modeSipInCall;
	
	if(service.getPrefs().useModeApi()) {
           Log.d(THIS_FILE, "User want speaker now..." + userWantSpeaker);
		if(!service.getPrefs().generateForSetCall()) {
			return userWantSpeaker ? AudioManager.MODE_NORMAL : AudioManager.MODE_IN_CALL;
		}else {
			return userWantSpeaker ? AudioManager.MODE_IN_CALL: AudioManager.MODE_NORMAL ;
		}
	}
	if(userWantBluetooth) {
	    targetMode = AudioManager.MODE_NORMAL;
	}

	Log.d(THIS_FILE, "Target mode... : " + targetMode);
	return targetMode;
}
 
Example 4
Source File: AudioRecorder.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
public void startAudioRecording() {
    AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (am.getMode() == AudioManager.MODE_NORMAL) {

        mediaRecorder = new MediaRecorder();

        String fileName = UUID.randomUUID().toString().substring(0, 8) + ".m4a";
        outputFilePath = new File(context.getFilesDir(), fileName);

        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

        //maybe we can modify these in the future, or allow people to tweak them
        mediaRecorder.setAudioChannels(1);
        mediaRecorder.setAudioEncodingBitRate(22050);
        mediaRecorder.setAudioSamplingRate(64000);

        mediaRecorder.setOutputFile(outputFilePath.getAbsolutePath());

        try {
            isAudioRecording = true;
            mediaRecorder.prepare();
            mediaRecorder.start();

            if (getVisualizerView() != null) {
                startLevelListener();
            }
        } catch (Exception e) {
            Log.e(LOG_TAG, "couldn't start audio", e);
        }
    }
}
 
Example 5
Source File: AppRTCAudioManager.java    From imsdk-android with MIT License 5 votes vote down vote up
public int ting()
{
   if(getSelectedAudioDevice() == AudioDevice.SPEAKER_PHONE)
   {
     if(audioManager.getMode() == AudioManager.MODE_IN_COMMUNICATION)
     {
       return changeToSpeakerMode();
     }
     else if(audioManager.getMode() == AudioManager.MODE_NORMAL) {
       return changeToEarpieceMode();
     }
   }
  return -1;
}
 
Example 6
Source File: AppRTCAudioManager.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * 外放模式
 * @return
 */
public int changeToSpeakerMode() {
  audioManager.setSpeakerphoneOn(true);
  audioManager.setMode(AudioManager.MODE_NORMAL);
  ((Activity)apprtcContext).setVolumeControlStream(AudioManager.STREAM_MUSIC);
  return AudioManager.MODE_NORMAL;
}
 
Example 7
Source File: AudioManagerUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前的音频模式
 * <pre>
 *     返回值有下述几种模式:
 *     MODE_NORMAL( 普通 )
 *     MODE_RINGTONE( 铃声 )
 *     MODE_IN_CALL( 打电话 )
 *     MODE_IN_COMMUNICATION( 通话 )
 * </pre>
 * @return 当前的音频模式
 */
public static int getMode() {
    AudioManager audioManager = AppUtils.getAudioManager();
    if (audioManager != null) {
        try {
            return audioManager.getMode();
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "getMode");
        }
    }
    return AudioManager.MODE_NORMAL;
}
 
Example 8
Source File: IflySynthesizer.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
/**
   * 设置默认的合成引擎
   *
   * @param type
   */
  private void setDefaultSynthesizerParam(NetType type) {
      if (isSpeaking()) {
          Log.e(TAG, "播放当中切换播放引擎失败");
          return;
      }
      synthesizer.setParameter(SpeechConstant.SPEED, Integer.toString(mVoiceConfig.getVolSpeed()));
      synthesizer.setParameter(SpeechConstant.VOLUME, Integer.toString(mVoiceConfig.getVolume()));
      synthesizer.setParameter(SpeechConstant.VOICE_NAME, mVoiceConfig.getVolName());
      synthesizer.setParameter("rdn", "0");
      synthesizer.setParameter(SpeechConstant.KEY_REQUEST_FOCUS, "0");
      if (mediator.isBlueToothHeadSet()) {
          synthesizer.setParameter(SpeechConstant.STREAM_TYPE, Integer.toString(AudioManager.STREAM_VOICE_CALL));
      } else {
          synthesizer.setParameter(SpeechConstant.STREAM_TYPE, Integer.toString(AudioManager.STREAM_MUSIC));
          AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
          if (am.getMode() != AudioManager.MODE_NORMAL) {
              am.setMode(AudioManager.MODE_NORMAL);
          }
      }
      //synthesizer.setParameter(SpeechConstant.ENGINE_TYPE, VoiceConfig.getSynEngineType());
      /*if(type==NetType.NETWORK_TYPE_NONE||type==NetType.NETWORK_TYPE_2G){//网络关闭的状态下启动离线识别
          Log.e(TAG, "离线。。。。。。。。。。。。。。。。。。。");
	synthesizer.setParameter(SpeechConstant.SPEED, OFFLINE_ENGINE_SPPED);
	synthesizer.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_LOCAL);
	synthesizer.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan");
	isLocalEngine=true;
}
else{*/
      Log.e(TAG, "在线。。。。。。。。。。。。。。。。。。。");
      //synthesizer.setParameter(SpeechConstant.SPEED,"70");
      synthesizer.setParameter(SpeechConstant.VOICE_NAME, mVoiceConfig.getVolName());
      //synthesizer.setParameter(SpeechConstant.VOICE_NAME, ChatRobot.isInit()&&ChatRobot.getInstance().getMode()==ChatConstant.CHILDREN_MODE?"vinn":"vixq");
      synthesizer.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
      //}
  }
 
Example 9
Source File: PreferencesProviderWrapper.java    From CSipSimple with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the audio codec quality setting
 * 
 * @return the audio quality
 */
public int getInCallMode() {
    String mode = getPreferenceStringValue(SipConfigManager.SIP_AUDIO_MODE);
    try {
        return Integer.parseInt(mode);
    } catch (NumberFormatException e) {
        Log.e(THIS_FILE, "In call mode " + mode + " not well formated");
    }

    return AudioManager.MODE_NORMAL;
}
 
Example 10
Source File: AudioPlayerHandler.java    From sctalk with Apache License 2.0 5 votes vote down vote up
public  void setAudioMode(int mode,Context ctx) {
    if (mode != AudioManager.MODE_NORMAL && mode != AudioManager.MODE_IN_CALL) {
        return;
    }
    AudioManager audioManager = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(mode);
}
 
Example 11
Source File: MessageAdapter.java    From sctalk with Apache License 2.0 5 votes vote down vote up
@Override
public void onSpeakerClick() {
    AudioPlayerHandler audioPlayerHandler = AudioPlayerHandler.getInstance();
    if (audioPlayerHandler.getAudioMode(ctx) == AudioManager.MODE_NORMAL) {
        audioPlayerHandler.setAudioMode(AudioManager.MODE_IN_CALL, ctx);
        SpeekerToast.show(ctx, ctx.getText(R.string.audio_in_call), Toast.LENGTH_SHORT);
    } else {
        audioPlayerHandler.setAudioMode(AudioManager.MODE_NORMAL, ctx);
        SpeekerToast.show(ctx, ctx.getText(R.string.audio_in_speeker), Toast.LENGTH_SHORT);
    }
}
 
Example 12
Source File: ConversationDetailActivity.java    From zom-android-matrix with Apache License 2.0 4 votes vote down vote up
public void startAudioRecording ()
{
    int permissionCheck = ContextCompat.checkSelfPermission(this,
            Manifest.permission.RECORD_AUDIO);

    if (permissionCheck ==PackageManager.PERMISSION_DENIED)
    {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.RECORD_AUDIO)) {


            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            Snackbar.make(mConvoView.getHistoryView(), R.string.grant_perms, Snackbar.LENGTH_LONG).show();
        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.RECORD_AUDIO},
                    MY_PERMISSIONS_REQUEST_AUDIO);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    }
    else {

        AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        if (am.getMode() == AudioManager.MODE_NORMAL) {

            mMediaRecorder = new MediaRecorder();

            String fileName = UUID.randomUUID().toString().substring(0, 8) + ".m4a";
            mAudioFilePath = new File(getFilesDir(), fileName);

            mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

            //maybe we can modify these in the future, or allow people to tweak them
            mMediaRecorder.setAudioChannels(1);
            mMediaRecorder.setAudioEncodingBitRate(22050);
            mMediaRecorder.setAudioSamplingRate(64000);

            mMediaRecorder.setOutputFile(mAudioFilePath.getAbsolutePath());

            try {
                mIsAudioRecording = true;
                mMediaRecorder.prepare();
                mMediaRecorder.start();
            } catch (Exception e) {
                Log.e(LOG_TAG, "couldn't start audio", e);
            }
        }
    }
}
 
Example 13
Source File: ConversationDetailActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
public void startAudioRecording ()
{
    int permissionCheck = ContextCompat.checkSelfPermission(this,
            Manifest.permission.RECORD_AUDIO);

    if (permissionCheck ==PackageManager.PERMISSION_DENIED)
    {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.RECORD_AUDIO)) {


            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            Snackbar.make(mConvoView.getHistoryView(), R.string.grant_perms, Snackbar.LENGTH_LONG).show();
        } else {

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.RECORD_AUDIO},
                    MY_PERMISSIONS_REQUEST_AUDIO);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    }
    else {

        AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        if (am.getMode() == AudioManager.MODE_NORMAL) {

            mMediaRecorder = new MediaRecorder();

            String fileName = UUID.randomUUID().toString().substring(0, 8) + ".m4a";
            mAudioFilePath = new File(getFilesDir(), fileName);

            mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

            //maybe we can modify these in the future, or allow people to tweak them
            mMediaRecorder.setAudioChannels(1);
            mMediaRecorder.setAudioEncodingBitRate(22050);
            mMediaRecorder.setAudioSamplingRate(64000);

            mMediaRecorder.setOutputFile(mAudioFilePath.getAbsolutePath());

            try {
                mIsAudioRecording = true;
                mMediaRecorder.prepare();
                mMediaRecorder.start();
            } catch (Exception e) {
                Log.e(ImApp.LOG_TAG, "couldn't start audio", e);
            }
        }
    }
}
 
Example 14
Source File: SettingsContentObserver.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
public void onChange(boolean selfChange) {
    super.onChange(selfChange);

    //CallsCounter.logCounter(context, "SettingsContentObserver.onChange", "SettingsContentObserver_onChange");

    ////// volume change
    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    if (audioManager != null) {
        int audioMode = audioManager.getMode();

        if ((audioMode == AudioManager.MODE_NORMAL) || (audioMode == AudioManager.MODE_RINGTONE)) {
            boolean ringMuted = audioManager.isStreamMute(AudioManager.STREAM_RING);
            boolean notificationMuted = audioManager.isStreamMute(AudioManager.STREAM_NOTIFICATION);

            int newVolumeRing = volumeChangeDetect(AudioManager.STREAM_RING, previousVolumeRing, ringMuted, audioManager);
            int newVolumeNotification = volumeChangeDetect(AudioManager.STREAM_NOTIFICATION, previousVolumeNotification, notificationMuted, audioManager);
            //previousVolumeMusic = volumeChangeDetect(AudioManager.STREAM_MUSIC, previousVolumeMusic, audioManager);
            //previousVolumeAlarm = volumeChangeDetect(AudioManager.STREAM_ALARM, previousVolumeAlarm, audioManager);
            //previousVolumeSystem = volumeChangeDetect(AudioManager.STREAM_SYSTEM, previousVolumeSystem, audioManager);

            if ((newVolumeRing != -1) && (newVolumeNotification != -1)) {
                if (((!ringMuted) && (previousVolumeRing != newVolumeRing)) ||
                    ((!notificationMuted) && (previousVolumeNotification != newVolumeNotification))) {
                    // volumes changed

                    if (!(ringMuted || notificationMuted)) {
                        boolean merged = (newVolumeRing == newVolumeNotification) && (previousVolumeRing == previousVolumeNotification);

                        if (!ApplicationPreferences.getSharedPreferences(context).contains(ActivateProfileHelper.PREF_MERGED_RING_NOTIFICATION_VOLUMES)) {
                            SharedPreferences.Editor editor = ApplicationPreferences.getEditor(context);

                            editor.putBoolean(ActivateProfileHelper.PREF_MERGED_RING_NOTIFICATION_VOLUMES, merged);
                            ApplicationPreferences.prefMergedRingNotificationVolumes = merged;

                            editor.apply();
                        }
                    }
                }

                if (!ringMuted)
                    previousVolumeRing = newVolumeRing;
                if (!notificationMuted)
                    previousVolumeNotification = newVolumeNotification;
            }

        }
        //previousVolumeVoice = volumeChangeDetect(AudioManager.STREAM_VOICE_CALL, previousVolumeVoice, audioManager);
        //int value = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
        //PPApplication.logE("[VOL] SettingsContentObserver.onChange", "STREAM_VOICE_CALL="+value);
        //////////////
    }

    ////// screen timeout change
    int screenTimeout = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 0);
    if (!ActivateProfileHelper.disableScreenTimeoutInternalChange) {
        if (previousScreenTimeout != screenTimeout) {
            if (Permissions.checkScreenTimeout(context)) {
                ActivateProfileHelper.setActivatedProfileScreenTimeout(context, 0);
                /*if (PPApplication.screenTimeoutHandler != null) {
                    PPApplication.screenTimeoutHandler.post(new Runnable() {
                        public void run() {
                            ActivateProfileHelper.removeScreenTimeoutAlwaysOnView(context);
                        }
                    });
                }*/// else
                //    ActivateProfileHelper.removeScreenTimeoutAlwaysOnView(context);
            }
        }
    }
    previousScreenTimeout = screenTimeout;

    if (!ActivateProfileHelper.brightnessDialogInternalChange) {
        savedBrightnessMode = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, -1);
        savedBrightness = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, -1);
        savedAdaptiveBrightness = Settings.System.getFloat(context.getContentResolver(), ActivateProfileHelper.ADAPTIVE_BRIGHTNESS_SETTING_NAME, -1);
        /*if (PPApplication.logEnabled()) {
            PPApplication.logE("[BRSD] SettingsContentObserver.onChange", "brightness mode=" + savedBrightnessMode);
            PPApplication.logE("[BRSD] SettingsContentObserver.onChange", "manual brightness value=" + savedBrightness);
            PPApplication.logE("[BRSD] SettingsContentObserver.onChange", "adaptive brightness value=" + savedAdaptiveBrightness);
        }*/
    }

    /*
    if (PPApplication.logEnabled()) {
        int value = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, -1);
        PPApplication.logE("[BRS] SettingsContentObserver.onChange", "brightness mode=" + value);
        value = Settings.System.getInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, -1);
        PPApplication.logE("[BRS] SettingsContentObserver.onChange", "manual brightness value=" + value);
        float fValue = Settings.System.getFloat(context.getContentResolver(), ActivateProfileHelper.ADAPTIVE_BRIGHTNESS_SETTING_NAME, -1);
        PPApplication.logE("[BRS] SettingsContentObserver.onChange", "adaptive brightness value=" + fValue);
    }
    */

    /////////////
}