Android Android Sound and Media suggest change

Play sounds via SoundPool

public class PlaySound extends Activity implements OnTouchListener {
    private SoundPool soundPool;
    private int soundID;
    boolean loaded = false;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
            View view = findViewById(;
            // Set the hardware buttons to control the music
            // Load the sound
            soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
            soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
                    public void onLoadComplete(SoundPool soundPool, int sampleId,
                                    int status) {
                            loaded = true;
            soundID = soundPool.load(this, R.raw.sound1, 1);


    public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    // Getting the user sound settings
                    AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
                    float actualVolume = (float) audioManager
                    float maxVolume = (float) audioManager
                    float volume = actualVolume / maxVolume;
                    // Is the sound loaded already?
                    if (loaded) {
                  , volume, volume, 1, 0, 1f);
                            Log.e("Test", "Played sound");
            return false;

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents