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;