Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play default TICK sound?

I want to connect Android OS default tick sound (for example, the sound you hear when you long click Home button and select previous app to start) with my button click. I know how to play sounds via MediaPlayer, but I do not know where to search for this default tick sound. It had to be in some default resources, but I could not find it.

MediaPlayer mp = MediaPlayer.create(getBaseContext(), sound);  
mp.setLooping(false);
mp.start();

Anyone can help?

PS. this sound will be activated inside of onClick method.
PPS. I know I can user /raw dir, but I do not think there's a need for it. Not to say, it's cooler to play this tick sound prepared for user's phone.

like image 705
sandalone Avatar asked Oct 27 '11 10:10

sandalone


People also ask

What procedure do you call in order to play a sound in Android?

What procedure do you call in order to play a sound in Android? mediaPlayer. start(); mediaPlayer. pause(); On call to start() method, the music will start playing from the beginning.

What is sound pool?

A SoundPool is a collection of samples that can be loaded into memory from a resource inside the APK or from a file in the file system.


1 Answers

You can play the default Android 'tick' sound using the view.playSoundEffect() method on any View - surprisingly enough, all views can play a selection of 'system' sounds:

view.playSoundEffect(SoundEffectConstants.CLICK);

and don't forget to add this to your view :

android:soundEffectsEnabled="true"

This is probably the simplest answer to your problem :)

like image 57
Roberto Tyley Avatar answered Sep 24 '22 08:09

Roberto Tyley