I wan to use the default TICK
sound but I dont know how or where to put this code
view.playSoundEffect(SoundEffectConstants.CLICK);
I found this code in another post.
This is the code I have:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final MediaPlayer mp = MediaPlayer.create(this, R.raw.blah);
Button Button01 = (Button)this.findViewById(R.id.Button01);
Button01.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
mp.start();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onClick(View v){}
public void disclaimerBTN (View v){
Toast.makeText(this, "FAILED: The remote object is " +
"not responding to this command",Toast.LENGTH_LONG).show();
}
}
So where would I put the view.play
..... code?
Much appreciated.
You can play a sound from every view just by calling it this way:
Button01.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
v.playSoundEffect(SoundEffectConstants.CLICK);
}
});
Just note that the sound will not play if touch sounds are off by default. This is set in the general device sound preferences (Settings-->Sound-->Audible or on newer OS: Options > Sound > Touch)
Also, if this setting is set, most click events will trigger the click sound anyway!
For Using AudioManager.playSoundEffect on Button click event you can try as:
AudioManager audioManager =
(AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
Button01.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
audioManager.playSoundEffect(SoundEffectConstants.CLICK);
//mp.start();
}
});
for reference you can see this example on Google source code:
http://code.google.com/p/android-traditional-chinese-ime/source/browse/trunk/src/com/googlecode/tcime/SoundMotionEffect.java?r=13
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With