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 SoundPool mSoundPool;
private int mSoundId;
// private SoundPool mSoundPool;
// private int mSoundId;
private AbstractUVCCameraHandler mHandler;
// 处理与Camera相关的逻辑,比如获取byte数据流等
private UVCCamera mUVCCamera;
@ -373,7 +373,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
mBandwidthFactor = bandwidthFactor;
mWeakParent = new WeakReference<>(parent);
mWeakCameraView = new WeakReference<>(cameraView);
loadShutterSound(parent);
// loadShutterSound(parent);
}
@Override
@ -508,7 +508,7 @@ public abstract class AbstractUVCCameraHandler extends Handler {
if (DEBUG) Log.v(TAG_THREAD, "handleCaptureStill:");
final Activity parent = mWeakParent.get();
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 {
final Bitmap bitmap = mWeakCameraView.get().captureStillImage();
// 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) {
streamType = AudioManager.STREAM_SYSTEM; // set appropriate according to your app policy
}
if (mSoundPool != null) {
try {
mSoundPool.release();
} catch (final Exception e) {
}
mSoundPool = null;
}
// load shutter sound from resource
mSoundPool = new SoundPool(2, streamType, 0);
mSoundId = mSoundPool.load(context, R.raw.camera_click, 1);
// if (mSoundPool != null) {
// try {
// mSoundPool.release();
// } catch (final Exception e) {
// }
// mSoundPool = null;
// }
// // load shutter sound from resource
// mSoundPool = new SoundPool(2, streamType, 0);
// mSoundId = mSoundPool.load(context, R.raw.camera_click, 1);
}
/**
@ -773,10 +773,10 @@ public abstract class AbstractUVCCameraHandler extends Handler {
mSync.notifyAll();
}
Looper.loop();
if (mSoundPool != null) {
mSoundPool.release();
mSoundPool = null;
}
// if (mSoundPool != null) {
// mSoundPool.release();
// mSoundPool = null;
// }
if (mHandler != null) {
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 {
private static final boolean DEBUG = true; // TODO set false on release
private static final String TAG = "MediaEncoder";
public static final int TYPE_VIDEO = 0; // 频数据
public static final int TYPE_AUDIO = 1; // 频数据
public static final int TYPE_AUDIO = 0; // 频数据
public static final int TYPE_VIDEO = 1; // 频数据
protected static final int TIMEOUT_USEC = 10000; // 10[msec]
protected static final int MSG_FRAME_AVAILABLE = 1;
protected static final int MSG_STOP_RECORDING = 9;
public interface MediaEncoderListener {
public void onPrepared(MediaEncoder encoder);
public void onStopped(MediaEncoder encoder);
// 音频或视频流,type=0为视频,type=1为音
void onPrepared(MediaEncoder encoder);
void onStopped(MediaEncoder encoder);
// 音频或视频流,type=0为音频,type=1为视
void onEncodeResult(byte[] data, int offset,
int length, long timestamp, int type);
}

Loading…
Cancel
Save