如果要加上自动对焦的声音,只需求加入播放声音的代码即可:
X:\workspace\m80\vendor\mediatek\proprietary\packages\apps\Camera\src\com\android\camera\FocusManager.java
public void fakeAutoFocusMoving(boolean moving) {
// Ignore if the camera has detected some faces.
if ((getFrameview() != null && getFrameview().faceExists())) {
return;
}
RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) mFocusIndicatorRotateLayout
.getLayoutParams();
int[] rules = p.getRules();
rules[RelativeLayout.CENTER_IN_PARENT] = RelativeLayout.TRUE;
p.setMargins(0, 0, 0, 0);
if (moving) {
mFocusIndicatorRotateLayout.showStart();
} else {
mFocusIndicatorRotateLayout.showSuccess(true);
mListener.playSound(MediaActionSound.FOCUS_COMPLETE); //此行代码是播放声音的代码,如果对焦不需要声音,去掉即可
}
}
但在加入声音后,会有一个问题。即离开相机界面后,只要后台相机还在运行,就会一直有滴滴的声音,这里需要在离开当前进程时,把自动对焦移除掉:
public void onPreviewStopped() {
Log.i(TAG, "onPreviewStopped");
mState = STATE_UNKNOWN;
resetTouchFocus();
// If auto focus was in progress, it would have been canceled.
updateFocusUI();
if(mHandler != null){ //
mHandler.removeMessages(AUTO_FOCUS_MOVING); //此行代码进行移除自动对焦
} //
}