KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have an AlertDialog with 2 buttons. I want them to play my custom sound when they're clicked. So I have this code on every button: SoundUtility.getInstance(Add_Edit_Note.this).playPositive(); SoundUtility is a class I wrote to play custom sounds. Here's the problem: it does play my custom sound, but simultaneously it also plays the system sound effect, so I have two sounds playing at the same time. I was able to disable it on the regular buttons by rewriting the Button: public class AppButton extends Button { public AppButton(Context context, AttributeSet attrs) { super(context, attrs); // Disable sound effect this.setSoundEffectsEnabled(false); } } and then in my XML file: <com.my.app.AppButton ... /> but I can't find a way to disable these system sound effects on AlertDialog buttons. Any suggestions? EDIT As requested, this is the SoundUtility code: public class SoundUtility { private static SoundUtility soundInstance; private MediaPlayer mpPositive; private MediaPlayer mpNegative; public static SoundUtility getInstance(Context context){ if(soundInstance==null) { soundInstance = new SoundUtility(context); } return soundInstance; } private SoundUtility (Context context) { mpPositive = MediaPlayer.create(context, R.raw.click_positive); mpNegative = MediaPlayer.create(context, R.raw.click_negative); } // Playing positive sound public void playPositive() { mpPositive.start(); } // Playing negative sound public void playNegative() { mpNegative.start(); } // Releasing MediaPlayer public void releaseMediaPlayer() { mpPositive.release(); mpNegative.release(); } } EDIT 2 The code of my AlertDialog: AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.se
Tags (comma-separated)
Save Edits
Cancel