Android 如何在我的游戏应用程序中禁用声音?

Android 如何在我的游戏应用程序中禁用声音?,android,audio,toggle,Android,Audio,Toggle,现在我开发了一个游戏应用程序,在google上玩的所有游戏中,它们都有一个切换按钮来打开/关闭声音 有没有什么技巧可以让我一步禁用游戏中的所有声音,或者我必须单独禁用每个声音 我使用MediaPlayer播放声音 private int playSound(int file) { int duration = 1000; sound = new MediaPlayer(); AssetFileDescriptor fd = getResources().openRaw

现在我开发了一个游戏应用程序,在google上玩的所有游戏中,它们都有一个切换按钮来打开/关闭声音

有没有什么技巧可以让我一步禁用游戏中的所有声音,或者我必须单独禁用每个声音

我使用MediaPlayer播放声音

private int playSound(int file) {

    int duration = 1000;
    sound = new MediaPlayer();

    AssetFileDescriptor fd = getResources().openRawResourceFd(file);
    try {
        sound.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
        sound.prepare();
        sound.start();

        sound.setOnCompletionListener(new OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                // Do the work after completion of audio
                Toast.makeText(GameActivity.this, "good", Toast.LENGTH_SHORT).show();
                mp.release();
            }
        });
        duration = sound.getDuration();

    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return duration;
}
试试这个

   media.setVolume(0,0);

还有其他类似默认按钮的声音呢?