音频焦点的基本用法

请求焦点:/** * Request audio focus. * Send a request to obtain the audio focus * @param l the listener to be notified of audio focus changes * @param streamType the main audio st
摘要由CSDN通过智能技术生成

请求焦点:

/**
     *  Request audio focus.
     *  Send a request to obtain the audio focus
     *  @param l the listener to be notified of audio focus changes
     *  @param streamType the main audio stream type affected by the focus request
     *  @param durationHint use {@link #AUDIOFOCUS_GAIN_TRANSIENT} to indicate this focus request
     *      is temporary, and focus will be abandonned shortly. Examples of transient requests are
     *      for the playback of driving directions, or notifications sounds.
     *      Use {@link #AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK} to indicate also that it's ok for
     *      the previous focus owner to keep playing if it ducks its audio output.
     *      Alternatively use {@link #AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE} for a temporary request
     *      that benefits from the system not playing disruptive sounds like notifications, for
     *      usecases such as voice memo recording, or speech recognition.
     *      Use {@link #AUDIOFOCUS_GAIN} for a focus request of unknown duration such
     *      as the playback of a song or a video.
     *  @return {@link #AUDIOFOCUS_REQUEST_FAILED} or {@link #AUDIOFOCUS_REQUEST_GRANTED}
     */
    public int requestAudioFocus(OnAudioFocusChangeListener l, int streamType, int durationHint)
下面几个参数都是和onAudioFocusChange(int focusChange)中的focusChange参数对应的

AUDIOFOCUS_GAIN_TRANSIENT:获取的短暂的焦点,就是告知被剥夺者,你很快会重获焦点。对应AUDIOFOCUS_LOSS_TRANSIENT

AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:获取焦点,告知被剥夺者,你可以继续播放并将音量降为0或者低音量播放。对应AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK

AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE:获取短暂焦点,但非常期望没有其他声音在播放。这个没有对应的loss标志。

AUDIOFOCUS_GAIN:获取较长期的焦点,对应AUDIOFOCUS_LOSS;



下面是其他博客的解释,但是我觉得是错误的,AUDIOFOCUS_LOSS不是失去很长时间,而是在request的时候参数是AUDIOFOCUS_GAIN,而AUDIOFOCUS_LOSS的解释是

失去焦点的时间未知,可能会长时间失去焦点。

focusChange参数告你音频焦点时如何改变的,并且能够是下面的值之一(它们是所有的在AudioManager类中定义的常量):

    AUDIOFOCUS_GAIN&#

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值