Android Audiomanager Audiofocus

Source: Internet
Author: User

Now started to do the music player module, encountered a few problems

When you play the music, you adjust the volume or the ringtone settings in the profile, and the result is two sounds ringing at the same time. The cause of the problem is that the music focus is not clear.

Now analyze several attributes of Music focus: source code in Frameworks/base/media/java/andorid/media/audiomanager.java


public static final int audiofocus_none = 0;


Indicates that the requested audio focus does not know how long it will last, usually long-term, and gets the audio focus;
public static final int audiofocus_gain = 1;

Indicates that the audiofocus to be applied is temporary and will soon be exhausted;

public static final int audiofocus_gain_transient = 2;

Not only that the audiofocus to be applied is temporary, but also indicates that you are currently using Audiofocus to continue playing, just to "duck" (lower the volume).

public static final int audiofocus_gain_transient_may_duck = 3;

public static final int audiofocus_gain_transient_exclusive = 4;

Audiomanager.onaudiofocuschangelistener is to monitor the use of Audiofocus after the successful application of listener, follow-up if there are other programs to compete Audiofocus, This listener Onaudiofocuschange () method is used to inform the user of this audio focus.


Lost audio Focus and will last for a long time

public static final int audiofocus_loss =-1 * audiofocus_gain;

Temporarily loses the audio Focus and will be available again soon. Audio playback must be stopped, but it is possible to get Audiofocus again soon, where media resources are not released;

public static final int audiofocus_loss_transient =-1 * audiofocus_gain_transient;

Temporarily loses the Audiofocus, but can continue to play, but to reduce the volume.

public static final int audiofocus_loss_transient_can_duck =
-1 * AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK;



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.