Search code examples
androidmute

Problems with supporting tablets and handsets simultaneously - sounds


I offer a mute option in my application, again in the settings screen, but although this mutes my sound effects, any clickable items that are pressed on the tablet still get the default click sound. How do I also stop the system clicks from happening? This is my current playSound method which won't play my sound effects with mMute has been set.

    try {
        streamVolume = mAudioManager
           .getStreamVolume(AudioManager.STREAM_MUSIC);
    streamVolume = streamVolume
    / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    } catch (NullPointerException e) {
        Log.e(DEBUG_TAG, "Null pointer returned from audio manager");
    }
    Integer soundToPlay = mSoundPoolMap.get(sound);
    if (streamVolume != 0.0f && soundToPlay != null && !mMute) {
        mSoundPool.play(mSoundPoolMap.get(sound), 
            streamVolume, streamVolume,
            1, 0, 1.0f);
    } else {
        Log.e(DEBUG_TAG, sound.toString() + " not found in sound pool map");
    }

}

Are there any other tips you can offer for sound handling in tablets? I assume that it's slightly different.


Solution

  • View#setSoundEffectsEnabled looks like one way, though it would require busy work building a set of all applicable views.