qugengting 2019-01-23 15:46 采纳率: 0%
浏览 2187

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

自定义视频录制时,开始录制和结束录制都会有“哔”的提示音,怎么去掉呢?网上搜索了好些答案,尝试了个遍,都没有效果,比如以下这些:


    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,人家都可以。。。

  • 写回答

1条回答 默认 最新

  • zyq_依之素 2019-01-23 16:14
    关注

    AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    audioManager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
    audioManager.setStreamMute(AudioManager.STREAM_MUSIC,true);
    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能