Android MediaRecorder 实现录制无声视频 禁止录入声音

最近遇到使用MediaRecorder录制视频的时候,需要默认录制无声视频,几经研究,也没找到资料解决,后来,发现,只需要同时取消设置AudioSource和AudioEncoder就可以实现录制无声视频。

特此记录下。

// 设置从麦克风采集声音
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
// 设置声音编码格式
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
发布了61 篇原创文章 · 获赞 65 · 访问量 20万+
展开阅读全文

android如何关闭MediaRecorder录制视频时的提示音

01-23

自定义视频录制时,开始录制和结束录制都会有“哔”的提示音,怎么去掉呢?网上搜索了好些答案,尝试了个遍,都没有效果,比如以下这些: ``` private int mVolumeStreamAlarm; private int mVolumeStreamDtmf; private int mVolumeStreamNotification; private int mVolumeStreamRing; private int mVolumeStreamSystem; private int mVolumeStreamMusic; private void closeSound() { //暂时关闭所有声音 // AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); // mVolumeStreamAlarm = audioManager.getStreamVolume(AudioManager.STREAM_ALARM); // mVolumeStreamDtmf = audioManager.getStreamVolume(AudioManager.STREAM_DTMF); // mVolumeStreamNotification = audioManager.getStreamVolume(AudioManager.STREAM_NOTIFICATION); // mVolumeStreamRing = audioManager.getStreamVolume(AudioManager.STREAM_RING); // mVolumeStreamSystem = audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM); // mVolumeStreamMusic = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); // audioManager.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); // audioManager.setStreamVolume(AudioManager.STREAM_DTMF, 0, 0); // audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, 0, 0); // audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0); // audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0); // audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // disable sound when recording. ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_ALARM, true); ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_DTMF, true); ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_MUSIC, true); ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_RING, true); ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_SYSTEM, true); ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_VOICE_CALL, true); } private void recoverSound() { //恢复声音 // AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); //// audioManager.setStreamVolume(AudioManager.STREAM_ALARM, mVolumeStreamAlarm, 0); //// audioManager.setStreamVolume(AudioManager.STREAM_DTMF, mVolumeStreamDtmf, 0); //// audioManager.setStreamVolume(AudioManager.STREAM_NOTIFICATION, mVolumeStreamNotification, 0); //// audioManager.setStreamVolume(AudioManager.STREAM_RING, mVolumeStreamRing, 0); //// audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, mVolumeStreamSystem, 0); //// audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mVolumeStreamMusic, 0); // re-enable sound after recording. ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_ALARM, false); ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_DTMF, false); ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_MUSIC, false); ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_RING, false); ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_SYSTEM, false); ((AudioManager) getApplicationContext().getSystemService(Context.AUDIO_SERVICE)).setStreamMute(AudioManager.STREAM_VOICE_CALL, false); } ``` 都没用。。。 为什么抖音,微信,QQ,人家都可以。。。 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 书香水墨 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览