java – AUDIOFOCUS_LOSS在Android中打电话后打电话

前端之家收集整理的这篇文章主要介绍了java – AUDIOFOCUS_LOSS在Android中打电话后打电话前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当手机响起时,我试图暂停媒体播放器.我使用 android站点的示例代码.就这样
public void onAudioFocusChange(int focusChange) {
        switch (focusChange) {
        case AudioManager.AUdioFOCUS_GAIN:
            // resume playback
            if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
                mMediaPlayer.start();
                mMediaPlayer.setVolume(1.0f,1.0f);
            }

            break;

        case AudioManager.AUdioFOCUS_LOSS:
            // Lost focus for an unbounded amount of time: stop playback and
            // release media player
            stopMediaPlayer();
            break;

        case AudioManager.AUdioFOCUS_LOSS_TRANSIENT:
            // Lost focus for a short time,but we have to stop
            // playback. We don't release the media player because playback
            // is likely to resume
            if (mMediaPlayer.isPlaying())
                mMediaPlayer.pause();
            break;

        case AudioManager.AUdioFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            // Lost focus for a short time,but it's ok to keep playing
            // at an attenuated level
            if (mMediaPlayer.isPlaying())
                mMediaPlayer.setVolume(0.1f,0.1f);
            break;
        }
    }

当手机振铃AUdioFOCUS_LOSS_TRANSIENT发送时;没关系当通话结束时,发送AUdioFOCUS_GAIN,播放器继续播放;这也行.发送AUdioFOCUS_GAIN后,发送AUdioFOCUS_LOSS.有什么想法为什么失去音频焦点?提前Thx.

@H_403_7@解决方法
两件事要检查:
1)你有一个播放按钮,当点击时,请求焦点并开始播放?我有一个问题,他们玩了一个“嘀”声,提供一个点击的反馈.当发生这种情况时,他们会将音频焦点从我的应用程序中移除.在您的XML中,将该值设置为false,表示该活动中的所有按钮:
android:soundEffectsEnabled = 'false'

2)检查是否安装其他要求重点的媒体播放器应用程序.失去后,他们是否要求焦点?如果是这样,除了警告您的用户不要安装此应用程序,您可以做的不多.

猜你在找的Android相关文章