Unable to play sound when button is pressed using playSoundEffect (SoundEffectConstants.CLICK)

I have the following two lines of code:

myButton.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
myButton.playSoundEffect(SoundEffectConstants.CLICK);

When I press the button, haptic feedback works fine, but there is no sound. I heard.

Has anyone had this problem when they started with Android?

+5
source share
3 answers

I had this problem, and for my part it turned out to be something completely stupid. I turned off the "Sound Selection" for the whole phone. On the home page in the settings → Sound → Sound selection. There is probably a programmatic way to do the same, but I haven't found it yet.

+8
source

. Samsung Galaxy S4 - → → → ( "" ). , , .

+1

, , , , . , - , .

View.playSoundEffect () did not work on my device if it was not called from the UI thread. (I don't see this limitation described in the Android literature, so it may differ from device to device or from OS version to OS version.) View.performHapticFeedback () does not seem to care. I called both from ThreadPool thread; haptic feedback and sound effects did not.

I fixed this by placing a sound effect call to run in the user interface thread as follows:

getActivity().runOnUiThread(new Runnable()
            {
                @Override
                public void run()
                {
                    mSketchView.playSoundEffect(SoundEffectConstants.CLICK);
                }
            });
0
source

All Articles