Android audiomanager controls the system sound process

Source: Internet
Author: User
Tags sendmsg

First, the upper-layer Java calls

Xxxplayer

Audiomanager audiomanage = (audiomanager) Context. getsystemservice (context. audio_service );

Audiomanager is the defined object that controls system sound. (If context reports an error, you can change it to xxxplayer. This)

Audiomanager. setstreamvolume (AA, BB, CC) is a member function of audiomanager that we can directly use. It is represented by three parameters: AA: has a built-in constant, you can find related definitions in audiomanager. We use audiomanager here. stream_music, BB: Set the volume value by yourself. CC: also indicates the volume. Here I set it to 0;

1. audiomanager. Java

Public void setstreamvolume (INT streamtype, int index, int flags); upper Interface

1) Call iaudioservice service = getservice (); the service is obtained when the program is enabled.

2. Run servicemanager. Java
Public static ibinder getservice (string name) Get audio service

3. audioservice. Java
Public void setstreamvolume (INT streamtype, int index, int flags) // Service Interface
1) Private void setstreamvolumeint (INT streamtype, int index, Boolean force, Boolean lastaudible) // service function
2) call the following functions:
Sendmsg (maudiohandler, msg_set_system_volume, streamtype, sendmsg_noop, 0, 0, streamstate, 0)
// Post message to set system volume (it in turn will post a message
// To persist)
3) audiohandler: setsystemvolume (volumestreamstate streamstate); // sendmsg (...) and then execute the Function
4) Call audiohandler: setstreamvolumeindex (INT stream, int index)
5) audiosystem. setstreamvolumeindex (stream, index); // audiosystem Interface

Static int android_media_audiosystem_setstreamvolumeindex (jnienv * ENV, jobject thiz, jint stream, jint index)
1) Call audiosystem: setstreamvolumeindex

6. status_t audiosystem: setstreamvolumeindex (stream_type stream, int index)
1) obtain the const sp <iaudiopolicyservice> & APS = audiosystem: get_audio_policy_service ();
2) Call APS-> setstreamvolumeindex (stream, index)

7. status_t audiopolicyservice: setstreamvolumeindex (audiosystem: stream_type stream, int index)
1) Call mppolicymanager-> setstreamvolumeindex (stream, index)
Status_t audiopolicymanager: setstreamvolumeindex (audiosystem: stream_type stream, int index)
1) record volume index: mstreams [stream]. mindexcur = index
2) compute and apply stream volume on all outputs:
Checkandsetvolume (stream, index, moutputs. keyat (I), moutputs. valueat (I)-> device ())

8. status_t audiopolicymanager: checkandsetvolume (INT stream, int index, audio_io_handle_t output, uint32_t device, int delayms, bool force)
1) volume calculation: Float volume = computevolume (stream, index, output, device );
2) Call: mpclientinterface-> setstreamvolume (audiosystem: stream_type) stream, volume, output, delayms );

9. status_t audiopolicyservice: setstreamvolume (audiosystem: stream_type stream, float volume, audio_io_handle_t output, int delayms)
Call maudiocommandthread-> volumecommand (INT) stream, volume, (INT) output, delayms );

10. status_t audiopolicyservice: audiocommandthread: volumecommand (INT stream, float volume, int output, int delayms)
Call insertcommand_l (command, delayms );

Supplement 1) When getservice () is used to obtain a service, servicemanager. getservice (context) is actually called );

System services are managed by servicemanager. To add services, you can call servicemanager. addservice (context, Service );

Each time a service is added, a unique context exists. When getservice is added, the corresponding service is obtained based on the context,

You can view servicemanager. Java, servicemanager. h/CPP

Supplement 2) The audioservice interface is defined in iaudioservice. aidl. When adding a custom function (we create a control interface, such as seteffectvolume (XXX), you can refer to setstreamvolume (A, B, C) and do not forget to modify it here. Otherwise, audiomanager will see cannot find symbol .. error !!!

3) An error may occur when calling the self-written interface in audiomanager. Java during compilation. In this case, comment out the call in the file and execute make Update-API.

After the execution is complete, remove the comments and re-compile them...

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.