如何使应用程序的所有声音静音? [英] How do I mute all sounds of my application?
问题描述
我正在创建一个仅用于学习的测验应用程序,但是我遇到了问题.
I'm creating a quiz app just for learning, and I've got a problem.
在我的mainactivity
中,我有一个媒体播放器.它甚至可以通过其他活动播放音乐,并且我有一个静音按钮可以停止音乐.当我成功找到正确答案时(在其他活动中的问题上),我也会产生声音效果.但是,当按静音按钮时,我不知道如何将此SFX与背景音乐一起静音.有什么提示吗? ;)
In my mainactivity
I have a media player. It plays music even going through other activities, and I have a mute button to stop the music. I also have a sound effect when I successfully hit the right answer (on a question which is in other activity). But I don't know how to mute this SFX along with the background music when I press the mute button. Any hints? ;)
如果有一种方法可以使我的整个应用静音,那就太好了.我发现了一些静音的方法,但是这种方法会使整个系统静音.而且是
If it has a way to mute my entire application will be so good. I found some ways to mute, but this way will mute the entire system. And it's
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
推荐答案
尝试一下.这可能对您有帮助.
Try this. It may be of help to you.
AudioManager manager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
manager.setStreamVolume(AudioManager.STREAM_ALARM, 0, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
这篇关于如何使应用程序的所有声音静音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!