Analysis of android audio Development Technology

Source: Internet
Author: User

Introduction: If you want to make things perfect rather than complete them, you must pay attention to every small detail and do not think too simply about the problem.

 

Android audio technology is not complicated in application development. However, to improve the user experience, we should pay attention to the following important aspects:

1. The volume adjustment function is essential, and we should try to take into account the volume at the beginning.

2. Consider the currently played audio and the audio to be converted. This includes temporary conversions of permanent conversion boxes, where duck features can be added.

Code that permanently gets the focus:

AudioManager am = mContext. getSystemService (Context. AUDIO_SERVICE );
...

// Request audio focus for playback
Int result = am. requestAudioFocus (afChangeListener,
// Use the music stream.
AudioManager. STREAM_MUSIC,
// Request permanent focus.
AudioManager. AUDIOFOCUS_GAIN );

If (result = AudioManager. AUDIOFOCUS_REQUEST_GRANTED ){
Am. unregisterMediaButtonEventReceiver (remotecontrolpolicer );
// Start playback.
}

Code temporarily obtained with duck:

// Request audio focus for playback
Int result = am. requestAudioFocus (afChangeListener,
// Use the music stream.
AudioManager. STREAM_MUSIC,
// Request permanent focus.
AudioManager. AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK );

If (result = AudioManager. AUDIOFOCUS_REQUEST_GRANTED ){
// Start playback.
}

3. The impact of different output devices on audio playback. Including headphones, Bluetooth, and other output devices. The following code checks the hardware:

If (isw.tha2dpon ()){
// Adjust output for Bluetooth.
} Else if (isSpeakerphoneOn ()){
// Adjust output for Speakerphone.
} Else if (isWiredHeadsetOn ()){
// Adjust output for headsets
} Else {
// If audio plays and noone can hear it, is it still playing?
}

 

Related Article

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.