Code example for SoundPool

Methods: playstop

0
        private boolean TestPriority() throws java.lang.InterruptedException { 
            if (DEBUG) Log.d(LOG_TAG, "Begin priority test");
            boolean result = true;
 
            // play a normal priority looping sound 
            int normalId = mSoundPool.play(mSounds[0], DEFAULT_VOLUME, DEFAULT_VOLUME,
                    NORMAL_PRIORITY, DEFAULT_LOOP, 1.0f);
            if (DEBUG) Log.d(LOG_TAG, "Start note " + normalId);
            if (normalId == 0) {
                Log.e(LOG_TAG, "Error occurred starting note");
                return false; 
            } 
            sleep(250);
 
            // play a low priority sound 
            int id = mSoundPool.play(mSounds[0], DEFAULT_VOLUME, DEFAULT_VOLUME,
                    LOW_PRIORITY, DEFAULT_LOOP, 1.0f);
            if (id > 0) {
                Log.e(LOG_TAG, "Normal > Low priority test failed");
                result = false;
                mSoundPool.stop(id);
            } else { 
                Log.e(LOG_TAG, "Normal > Low priority test passed");
            } 
            sleep(250);
 
            // play a high priority sound 
            id = mSoundPool.play(mSounds[0], DEFAULT_VOLUME, DEFAULT_VOLUME,
                    HIGH_PRIORITY, DEFAULT_LOOP, 1.0f);
            if (id == 0) {
                Log.e(LOG_TAG, "High > Normal priority test failed");
                result = false;
            } else { 
                Log.e(LOG_TAG, "High > Normal priority test passed");
            } 
            sleep(250);
            mSoundPool.stop(id);
 
            // stop normal note 
            mSoundPool.stop(normalId);
 
            if (DEBUG) Log.d(LOG_TAG, "End priority test");
            return result;
        }