当前位置: 首页>>代码示例>>Java>>正文


Java AudioManager.setSpeakerphoneOn方法代码示例

本文整理汇总了Java中android.media.AudioManager.setSpeakerphoneOn方法的典型用法代码示例。如果您正苦于以下问题:Java AudioManager.setSpeakerphoneOn方法的具体用法?Java AudioManager.setSpeakerphoneOn怎么用?Java AudioManager.setSpeakerphoneOn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.AudioManager的用法示例。


在下文中一共展示了AudioManager.setSpeakerphoneOn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: switchSpeaker

import android.media.AudioManager; //导入方法依赖的package包/类
/**
 * 扬声器开关
 * @param context
 * @param enableSpeaker 是否打开扬声器,true:打开,false:关闭
 */
public static void switchSpeaker(Context context, boolean enableSpeaker) {
    try {
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        audioManager.setMode(AudioManager.ROUTE_SPEAKER);
        int currVolume = audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
        if (enableSpeaker) {
            //setSpeakerphoneOn() only work when audio mode set to MODE_IN_CALL.
            audioManager.setMode(AudioManager.MODE_IN_CALL);
            audioManager.setSpeakerphoneOn(true);
            audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
                    audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL),
                    AudioManager.STREAM_VOICE_CALL);
        } else {
            audioManager.setSpeakerphoneOn(false);
            audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, currVolume,
                    AudioManager.STREAM_VOICE_CALL);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:sundevin,项目名称:utilsLibrary,代码行数:27,代码来源:SpeakerUtils.java

示例2: handleWiredHeadsetChange

import android.media.AudioManager; //导入方法依赖的package包/类
private void handleWiredHeadsetChange(Intent intent) {
  Log.w(TAG, "handleWiredHeadsetChange...");

  if (callState == CallState.STATE_CONNECTED ||
          callState == CallState.STATE_DIALING   ||
          callState == CallState.STATE_REMOTE_RINGING)
  {
    AudioManager audioManager = ServiceUtil.getAudioManager(this);
    boolean      present      = intent.getBooleanExtra(EXTRA_AVAILABLE, false);

    if (present && audioManager.isSpeakerphoneOn()) {
      audioManager.setSpeakerphoneOn(false);
      audioManager.setBluetoothScoOn(false);
    } else if (!present && !audioManager.isSpeakerphoneOn() && !audioManager.isBluetoothScoOn() && localVideoEnabled) {
      audioManager.setSpeakerphoneOn(true);
    }

    if (recipient != null) {
      sendMessage(viewModelStateFor(callState), recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
    }
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:23,代码来源:WebRtcCallService.java

示例3: startOutgoingRinger

import android.media.AudioManager; //导入方法依赖的package包/类
public void startOutgoingRinger(OutgoingRinger.Type type) {
    AudioManager audioManager = ServiceUtil.getAudioManager(context);
    audioManager.setMicrophoneMute(false);

    if (type == OutgoingRinger.Type.SONAR) {
        audioManager.setSpeakerphoneOn(false);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
    } else {
        audioManager.setMode(AudioManager.MODE_IN_CALL);
    }

    outgoingRinger.start(type);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:17,代码来源:SignalAudioManager.java

示例4: stop

import android.media.AudioManager; //导入方法依赖的package包/类
public void stop(boolean playDisconnected) {
    AudioManager audioManager = ServiceUtil.getAudioManager(context);

    incomingRinger.stop();
    outgoingRinger.stop();

    if (playDisconnected) {
        soundPool.play(disconnectedSoundId, 1.0f, 1.0f, 0, 0, 1.0f);
    }

    if (audioManager.isBluetoothScoOn()) {
        audioManager.setBluetoothScoOn(false);
        audioManager.stopBluetoothSco();
    }

    audioManager.setSpeakerphoneOn(false);
    audioManager.setMicrophoneMute(false);
    audioManager.setMode(AudioManager.MODE_NORMAL);
    audioManager.abandonAudioFocus(null);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:21,代码来源:SignalAudioManager.java

示例5: startCommunication

import android.media.AudioManager; //导入方法依赖的package包/类
public void startCommunication(boolean preserveSpeakerphone) {
  AudioManager audioManager = ServiceUtil.getAudioManager(context);

  incomingRinger.stop();
  outgoingRinger.stop();

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
  } else {
    audioManager.setMode(AudioManager.MODE_IN_CALL);
  }

  if (!preserveSpeakerphone) {
    audioManager.setSpeakerphoneOn(false);
  }

  soundPool.play(connectedSoundId, 1.0f, 1.0f, 0, 0, 1.0f);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:19,代码来源:SignalAudioManager.java

示例6: startOutgoingRinger

import android.media.AudioManager; //导入方法依赖的package包/类
public void startOutgoingRinger(OutgoingRinger.Type type) {
  AudioManager audioManager = ServiceUtil.getAudioManager(context);
  audioManager.setMicrophoneMute(false);

  if (type == OutgoingRinger.Type.SONAR) {
    audioManager.setSpeakerphoneOn(false);
  }

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
  } else {
    audioManager.setMode(AudioManager.MODE_IN_CALL);
  }

  outgoingRinger.start(type);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:17,代码来源:SignalAudioManager.java

示例7: handleWiredHeadsetChange

import android.media.AudioManager; //导入方法依赖的package包/类
private void handleWiredHeadsetChange(Intent intent) {
  Log.w(TAG, "handleWiredHeadsetChange...");

  if (callState == CallState.STATE_CONNECTED ||
      callState == CallState.STATE_DIALING   ||
      callState == CallState.STATE_REMOTE_RINGING)
  {
    AudioManager audioManager = ServiceUtil.getAudioManager(this);
    boolean      present      = intent.getBooleanExtra(EXTRA_AVAILABLE, false);

    if (present && audioManager.isSpeakerphoneOn()) {
      audioManager.setSpeakerphoneOn(false);
      audioManager.setBluetoothScoOn(false);
    } else if (!present && !audioManager.isSpeakerphoneOn() && !audioManager.isBluetoothScoOn() && localVideoEnabled) {
      audioManager.setSpeakerphoneOn(true);
    }

    if (recipient != null) {
      sendMessage(viewModelStateFor(callState), recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
    }
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:23,代码来源:WebRtcCallService.java

示例8: startIncomingRinger

import android.media.AudioManager; //导入方法依赖的package包/类
public void startIncomingRinger() {
  AudioManager audioManager = ServiceUtil.getAudioManager(context);
  boolean      speaker      = !audioManager.isWiredHeadsetOn() && !audioManager.isBluetoothScoOn();

  audioManager.setMode(AudioManager.MODE_RINGTONE);
  audioManager.setMicrophoneMute(false);
  audioManager.setSpeakerphoneOn(speaker);

  incomingRinger.start();
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:11,代码来源:SignalAudioManager.java

示例9: enableVocieMode

import android.media.AudioManager; //导入方法依赖的package包/类
public static void enableVocieMode() {
    AudioManager audioManager = (AudioManager) App.getInstance().getSystemService(Context.AUDIO_SERVICE);
    if (Options.getInstance().audio.aec) {
        audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
        audioManager.setSpeakerphoneOn(true);
    } else {
        audioManager.setMode(AudioManager.MODE_NORMAL);
        audioManager.setSpeakerphoneOn(false);
    }
}
 
开发者ID:wuyisheng,项目名称:libRtmp,代码行数:11,代码来源:AndroidUntil.java

示例10: handleSetMuteVideo

import android.media.AudioManager; //导入方法依赖的package包/类
private void handleSetMuteVideo(Intent intent) {
  AudioManager audioManager = ServiceUtil.getAudioManager(this);
  boolean      muted        = intent.getBooleanExtra(EXTRA_MUTE, false);

  this.localVideoEnabled = !muted;

  if (this.peerConnection != null) {
    this.peerConnection.setVideoEnabled(this.localVideoEnabled);
  }

  if (this.callId != null && this.dataChannel != null) {
    this.dataChannel.send(new DataChannel.Buffer(ByteBuffer.wrap(Data.newBuilder()
                                                                     .setVideoStreamingStatus(WebRtcDataProtos.VideoStreamingStatus.newBuilder()
                                                                                                                                   .setId(this.callId)
                                                                                                                                   .setEnabled(localVideoEnabled))
                                                                     .build().toByteArray()), false));
  }

  if (callState == CallState.STATE_CONNECTED) {
    if (localVideoEnabled) this.lockManager.updatePhoneState(LockManager.PhoneState.IN_VIDEO);
    else                   this.lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
  }

  if (localVideoEnabled && !audioManager.isSpeakerphoneOn() && !audioManager.isBluetoothScoOn()) {
    audioManager.setSpeakerphoneOn(true);
  }

  sendMessage(viewModelStateFor(callState), this.recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:30,代码来源:WebRtcCallService.java

示例11: startIncomingRinger

import android.media.AudioManager; //导入方法依赖的package包/类
public void startIncomingRinger() {
    AudioManager audioManager = ServiceUtil.getAudioManager(context);
    boolean      speaker      = !audioManager.isWiredHeadsetOn() && !audioManager.isBluetoothScoOn();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
    } else {
        audioManager.setMode(AudioManager.MODE_IN_CALL);
    }

    audioManager.setMicrophoneMute(false);
    audioManager.setSpeakerphoneOn(speaker);

    incomingRinger.start(speaker);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:16,代码来源:SignalAudioManager.java

示例12: onSpeakerChange

import android.media.AudioManager; //导入方法依赖的package包/类
@Override
public void onSpeakerChange(boolean isSpeaker) {
  AudioManager audioManager = ServiceUtil.getAudioManager(WebRtcCallActivity.this);
  audioManager.setSpeakerphoneOn(isSpeaker);

  if (isSpeaker && audioManager.isBluetoothScoOn()) {
    audioManager.stopBluetoothSco();
    audioManager.setBluetoothScoOn(false);
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:11,代码来源:WebRtcCallActivity.java

示例13: start

import android.media.AudioManager; //导入方法依赖的package包/类
public void start(boolean speakerphone) {
    AudioManager audioManager = ServiceUtil.getAudioManager(context);

    if (player != null) player.release();
    player = createPlayer();

    int ringerMode = audioManager.getRingerMode();

    if (shouldVibrate(context, player, ringerMode)) {
        Log.i(TAG, "Starting vibration");
        vibrator.vibrate(VIBRATE_PATTERN, 1);
    }

    if (player != null && ringerMode == AudioManager.RINGER_MODE_NORMAL) {
        try {
            if (!player.isPlaying()) {
                player.prepare();
                player.start();
                Log.w(TAG, "Playing ringtone now...");
            } else {
                Log.w(TAG, "Ringtone is already playing, declining to restart.");
            }
        } catch (IllegalStateException | IOException e) {
            Log.w(TAG, e);
            player = null;
        }
    } else {
        Log.w(TAG, "Not ringing, mode: " + ringerMode);
    }

    if (speakerphone) {
        audioManager.setSpeakerphoneOn(true);
    }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:35,代码来源:IncomingRinger.java

示例14: audioOnSpeakers

import android.media.AudioManager; //导入方法依赖的package包/类
@ProtoMethod(description = "Routes the audio through the speakers", example = "media.playSound(fileName);")
@ProtoMethodParam(params = {""})
public void audioOnSpeakers(boolean b) {
    AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
    audioManager.setMode(AudioManager.MODE_IN_CALL);
    audioManager.setSpeakerphoneOn(!b);
}
 
开发者ID:victordiaz,项目名称:phonk,代码行数:8,代码来源:PMedia.java

示例15: handleSetMuteVideo

import android.media.AudioManager; //导入方法依赖的package包/类
private void handleSetMuteVideo(Intent intent) {
  AudioManager audioManager = ServiceUtil.getAudioManager(this);
  boolean      muted        = intent.getBooleanExtra(EXTRA_MUTE, false);

  this.localVideoEnabled = !muted;

  if (this.peerConnection != null) {
    this.peerConnection.setVideoEnabled(this.localVideoEnabled);
  }

  if (this.callId != null && this.dataChannel != null) {
    this.dataChannel.send(new DataChannel.Buffer(ByteBuffer.wrap(Data.newBuilder()
                                                                     .setVideoStreamingStatus(WebRtcDataProtos.VideoStreamingStatus.newBuilder()
                                                                                                                                   .setId(this.callId)
                                                                                                                                   .setEnabled(localVideoEnabled))
                                                                     .build().toByteArray()), false));
  }

  if (callState == CallState.STATE_CONNECTED) {
    if (localVideoEnabled) this.lockManager.updatePhoneState(LockManager.PhoneState.IN_VIDEO);
    else                   this.lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
  }

  if (localVideoEnabled &&
      !audioManager.isSpeakerphoneOn() &&
      !audioManager.isBluetoothScoOn() &&
      !audioManager.isWiredHeadsetOn())
  {
    audioManager.setSpeakerphoneOn(true);
  }

  sendMessage(viewModelStateFor(callState), this.recipient, localVideoEnabled, remoteVideoEnabled, bluetoothAvailable, microphoneEnabled);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:34,代码来源:WebRtcCallService.java


注:本文中的android.media.AudioManager.setSpeakerphoneOn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。