android框架_5.0的AudioManager分析_013

匿名 (未验证) 提交于 2019-12-03 00:22:01

AudioManager分析


一、AudioManager类

1、frameworks/base/media/java/android/media/AudioManager.java

该类主要是用于上层应用的API接口与frameworks的逻辑交互工作,这里有很多的功能设置选项;

AudioManager类位于android.Media 包中,该类提供访问控制音量和钤声模式的操作。

通过getSystemService(Context.AUDIO_SERVICE)方法获得AudioManager实例对象。

AudioManager audiomanage = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);

audiomanager就是我们定义的控制系统声音的对象。


/**  * AudioManager provides access to volume and ringer mode control.  * <p>  * Use <code>Context.getSystemService(Context.AUDIO_SERVICE)</code> to get  * an instance of this class.  */ public class AudioManager {      private final Context mContext;     private long mVolumeKeyUpTime;     private final boolean mUseMasterVolume; //从config.xml文件中获取,默认为false     private final boolean mUseVolumeKeySounds;//从config.xml文件中获取,默认为true;     private final boolean mUseFixedVolume; //从config.xml文件中获取,默认为false;     private final Binder mToken = new Binder();//默认还没有用这个对象,     private static String TAG = "AudioManager";     private static final AudioPortEventHandler sAudioPortEventHandler = new AudioPortEventHandler();
2、初始化变量:
    /**      * @hide      */     public AudioManager(Context context) {         mContext = context;         mUseMasterVolume = mContext.getResources().getBoolean(                 com.android.internal.R.bool.config_useMasterVolume);         mUseVolumeKeySounds = mContext.getResources().getBoolean(                 com.android.internal.R.bool.config_useVolumeKeySounds);         mUseFixedVolume = mContext.getResources().getBoolean(                 com.android.internal.R.bool.config_useFixedVolume);         sAudioPortEventHandler.init();     }      private static IAudioService getService()     {         if (sService != null) {             return sService;         }         IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);         sService = IAudioService.Stub.asInterface(b);         return sService;     }

3、从配置文件中获取属性值,和初始化对象;同时获取一个IBinder的服务对象;









易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!