Search in sources :

Example 76 with AudioManager

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");
            }
        }
    }
}
Also used : AudioManager(android.media.AudioManager)

Example 77 with AudioManager

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();
    }
}
Also used : AudioManager(android.media.AudioManager) File(java.io.File) MediaPlayer(android.media.MediaPlayer)

Example 78 with AudioManager

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();
}
Also used : AudioManager(android.media.AudioManager) Ringtone(android.media.Ringtone)

Example 79 with AudioManager

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();
    }
}
Also used : AudioManager(android.media.AudioManager)

Example 80 with AudioManager

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);
}
Also used : AudioManager(android.media.AudioManager)

Aggregations

AudioManager (android.media.AudioManager)159 MediaPlayer (android.media.MediaPlayer)50 AudioEffect (android.media.audiofx.AudioEffect)42 LargeTest (android.test.suitebuilder.annotation.LargeTest)42 EnergyProbe (com.android.mediaframeworktest.functional.EnergyProbe)24 Context (android.content.Context)9 Intent (android.content.Intent)7 IOException (java.io.IOException)7 Cea708CaptionRenderer (android.media.Cea708CaptionRenderer)5 ClosedCaptionRenderer (android.media.ClosedCaptionRenderer)5 MediaFormat (android.media.MediaFormat)5 Ringtone (android.media.Ringtone)5 SubtitleController (android.media.SubtitleController)5 TtmlRenderer (android.media.TtmlRenderer)5 WebVttRenderer (android.media.WebVttRenderer)5 PowerManager (android.os.PowerManager)5 InputStream (java.io.InputStream)5 View (android.view.View)4 NotificationManager (android.app.NotificationManager)3 PendingIntent (android.app.PendingIntent)3