*/
frameworks/base/media/java/android/media/AudioService .java
public class AudioService extends IAudioService.Stub {
}
AudioService .java 提供了audio service 的服务实现, IAudioService.aidl 定义了服务的方法.
private static IAudioService sService; /** * @hide */ public AudioManager(Context context) { mContext = context; mMediaPlayers = new ArrayList<MediaPlayerInfo>(1); 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; }
IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE); sService = IAudioService.Stub.asInterface(b)
AudioManager 封装了AudioService的服务,并通过getservice 获取到AudioService的 Service 实例.
实现了服务和服务的manager, java 应用层的使用方法 ,找到了个例子说明.
导入提供服务的java包
import android.media.AudioManager;
定义私有对象.
private AudioManager mAudioManager;
获取服务并转换成AudioManger 类型.
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
获取原始音量.
mOriginalMasterVol = mAudioManager.getMasterVolume();
if (mShutterVol >= 0 && mShutterVol <= 100 )
mAudioManager.setMasterVolume(mShutterVol,0); 调用服务提供的方法设置音量.
这样就实现了audio的 Service manger 的调用流程. 当然这只是Service 的大概说明.
总的框架掌握了. 细节慢慢分析吧.