Browse Source

屏蔽拍照声音

main
jiangdongguo 7 years ago
parent
commit
eb7ad6c5c0
  1. 36
      libusbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java
  2. 10
      libusbcamera/src/main/java/com/serenegiant/usb/encoder/MediaEncoder.java

36
libusbcamera/src/main/java/com/serenegiant/usb/common/AbstractUVCCameraHandler.java

@ -339,8 +339,8 @@ public abstract class AbstractUVCCameraHandler extends Handler {
private boolean mIsRecording; private boolean mIsRecording;
// 播放声音 // 播放声音
private SoundPool mSoundPool; // private SoundPool mSoundPool;
private int mSoundId; // private int mSoundId;
private AbstractUVCCameraHandler mHandler; private AbstractUVCCameraHandler mHandler;
// 处理与Camera相关的逻辑,比如获取byte数据流等 // 处理与Camera相关的逻辑,比如获取byte数据流等
private UVCCamera mUVCCamera; private UVCCamera mUVCCamera;
@ -373,7 +373,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
mBandwidthFactor = bandwidthFactor; mBandwidthFactor = bandwidthFactor;
mWeakParent = new WeakReference<>(parent); mWeakParent = new WeakReference<>(parent);
mWeakCameraView = new WeakReference<>(cameraView); mWeakCameraView = new WeakReference<>(cameraView);
loadShutterSound(parent); // loadShutterSound(parent);
} }
@Override @Override
@ -508,7 +508,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
if (DEBUG) Log.v(TAG_THREAD, "handleCaptureStill:"); if (DEBUG) Log.v(TAG_THREAD, "handleCaptureStill:");
final Activity parent = mWeakParent.get(); final Activity parent = mWeakParent.get();
if (parent == null) return; if (parent == null) return;
mSoundPool.play(mSoundId, 0.2f, 0.2f, 0, 0, 1.0f); // play shutter sound // mSoundPool.play(mSoundId, 0.2f, 0.2f, 0, 0, 1.0f); // play shutter sound
try { try {
final Bitmap bitmap = mWeakCameraView.get().captureStillImage(); final Bitmap bitmap = mWeakCameraView.get().captureStillImage();
// get buffered output stream for saving a captured still image as a file on external storage. // get buffered output stream for saving a captured still image as a file on external storage.
@ -713,16 +713,16 @@ public abstract class AbstractUVCCameraHandler extends Handler {
} catch (final Exception e) { } catch (final Exception e) {
streamType = AudioManager.STREAM_SYSTEM; // set appropriate according to your app policy streamType = AudioManager.STREAM_SYSTEM; // set appropriate according to your app policy
} }
if (mSoundPool != null) { // if (mSoundPool != null) {
try { // try {
mSoundPool.release(); // mSoundPool.release();
} catch (final Exception e) { // } catch (final Exception e) {
} // }
mSoundPool = null; // mSoundPool = null;
} // }
// load shutter sound from resource // // load shutter sound from resource
mSoundPool = new SoundPool(2, streamType, 0); // mSoundPool = new SoundPool(2, streamType, 0);
mSoundId = mSoundPool.load(context, R.raw.camera_click, 1); // mSoundId = mSoundPool.load(context, R.raw.camera_click, 1);
} }
/** /**
@ -773,10 +773,10 @@ public abstract class AbstractUVCCameraHandler extends Handler {
mSync.notifyAll(); mSync.notifyAll();
} }
Looper.loop(); Looper.loop();
if (mSoundPool != null) { // if (mSoundPool != null) {
mSoundPool.release(); // mSoundPool.release();
mSoundPool = null; // mSoundPool = null;
} // }
if (mHandler != null) { if (mHandler != null) {
mHandler.mReleased = true; mHandler.mReleased = true;
} }

10
libusbcamera/src/main/java/com/serenegiant/usb/encoder/MediaEncoder.java

@ -34,17 +34,17 @@ import java.nio.ByteBuffer;
public abstract class MediaEncoder implements Runnable { public abstract class MediaEncoder implements Runnable {
private static final boolean DEBUG = true; // TODO set false on release private static final boolean DEBUG = true; // TODO set false on release
private static final String TAG = "MediaEncoder"; private static final String TAG = "MediaEncoder";
public static final int TYPE_VIDEO = 0; // 频数据 public static final int TYPE_AUDIO = 0; // 频数据
public static final int TYPE_AUDIO = 1; // 频数据 public static final int TYPE_VIDEO = 1; // 频数据
protected static final int TIMEOUT_USEC = 10000; // 10[msec] protected static final int TIMEOUT_USEC = 10000; // 10[msec]
protected static final int MSG_FRAME_AVAILABLE = 1; protected static final int MSG_FRAME_AVAILABLE = 1;
protected static final int MSG_STOP_RECORDING = 9; protected static final int MSG_STOP_RECORDING = 9;
public interface MediaEncoderListener { public interface MediaEncoderListener {
public void onPrepared(MediaEncoder encoder); void onPrepared(MediaEncoder encoder);
public void onStopped(MediaEncoder encoder); void onStopped(MediaEncoder encoder);
// 音频或视频流,type=0为视频,type=1为音 // 音频或视频流,type=0为音频,type=1为视
void onEncodeResult(byte[] data, int offset, void onEncodeResult(byte[] data, int offset,
int length, long timestamp, int type); int length, long timestamp, int type);
} }

Loading…
Cancel
Save