use of android.media.AudioManager in project android_frameworks_base by DirtyUnicorns.
the class PhoneWindow method onKeyUpPanel.
/**
* Called when the panel key is released.
* @param featureId The feature ID of the relevant panel (defaults to FEATURE_OPTIONS_PANEL}.
* @param event The key event.
*/
public final void onKeyUpPanel(int featureId, KeyEvent event) {
// The panel key was released, so clear the chording key
if (mPanelChordingKey != 0) {
mPanelChordingKey = 0;
final PanelFeatureState st = getPanelState(featureId, false);
if (event.isCanceled() || (mDecor != null && mDecor.mPrimaryActionMode != null) || (st == null)) {
return;
}
boolean playSoundEffect = false;
if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null && mDecorContentParent.canShowOverflowMenu() && !ViewConfiguration.get(getContext()).hasPermanentMenuKey()) {
if (!mDecorContentParent.isOverflowMenuShowing()) {
if (!isDestroyed() && preparePanel(st, event)) {
playSoundEffect = mDecorContentParent.showOverflowMenu();
}
} else {
playSoundEffect = mDecorContentParent.hideOverflowMenu();
}
} else {
if (st.isOpen || st.isHandled) {
// Play the sound effect if the user closed an open menu (and not if
// they just released a menu shortcut)
playSoundEffect = st.isOpen;
// Close menu
closePanel(st, true);
} else if (st.isPrepared) {
boolean show = true;
if (st.refreshMenuContent) {
// Something may have invalidated the menu since we prepared it.
// Re-prepare it to refresh.
st.isPrepared = false;
show = preparePanel(st, event);
}
if (show) {
// Write 'menu opened' to event log
EventLog.writeEvent(50001, 0);
// Show menu
openPanel(st, event);
playSoundEffect = true;
}
}
}
if (playSoundEffect) {
AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
if (audioManager != null) {
audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
} else {
Log.w(TAG, "Couldn't get audio manager");
}
}
}
}
use of android.media.AudioManager in project SmartCampus by Vegen.
the class EaseChatRowVoicePlayClickListener method playVoice.
public void playVoice(String filePath) {
if (!(new File(filePath).exists())) {
return;
}
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;
// stop animation
stopPlayVoice();
}
});
isPlaying = true;
currentPlayListener = this;
mediaPlayer.start();
showAnimation();
// 如果是接收的消息
if (message.direct() == EMMessage.Direct.RECEIVE) {
if (!message.isAcked() && chatType == 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);
EMClient.getInstance().chatManager().setVoiceMessageListened(message);
}
}
} catch (Exception e) {
System.out.println();
}
}
use of android.media.AudioManager in project platform_frameworks_base by android.
the class PhoneWindowManager method performAuditoryFeedbackForAccessibilityIfNeed.
private void performAuditoryFeedbackForAccessibilityIfNeed() {
if (!isGlobalAccessibilityGestureEnabled()) {
return;
}
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
if (audioManager.isSilentMode()) {
return;
}
Ringtone ringTone = RingtoneManager.getRingtone(mContext, Settings.System.DEFAULT_NOTIFICATION_URI);
ringTone.setStreamType(AudioManager.STREAM_MUSIC);
ringTone.play();
}
use of android.media.AudioManager in project platform_frameworks_base by android.
the class DevicePolicyManagerService method isMasterVolumeMuted.
@Override
public boolean isMasterVolumeMuted(ComponentName who) {
Preconditions.checkNotNull(who, "ComponentName is null");
synchronized (this) {
getActiveAdminForCallerLocked(who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return audioManager.isMasterMute();
}
}
use of android.media.AudioManager in project CameraView by CJT2325.
the class AudioUtil method setAudioManage.
public static void setAudioManage(Context context) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0);
audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
}
Aggregations