summaryrefslogtreecommitdiffstats
path: root/media/tests/SoundPoolTest
diff options
context:
space:
mode:
authorDave Sparks <davidsparks@android.com>2010-02-09 13:00:09 -0800
committerDave Sparks <davidsparks@android.com>2010-02-16 16:19:32 -0800
commitf992cbb9aae593c7787ac9c5f6b475e7bb0a92c5 (patch)
tree198ccb03a7257622d3f68b6e693c3e140346e0d6 /media/tests/SoundPoolTest
parent146c4a53b5e4d09e712147b031a9db9088a1769c (diff)
downloadframeworks_base-f992cbb9aae593c7787ac9c5f6b475e7bb0a92c5.zip
frameworks_base-f992cbb9aae593c7787ac9c5f6b475e7bb0a92c5.tar.gz
frameworks_base-f992cbb9aae593c7787ac9c5f6b475e7bb0a92c5.tar.bz2
Add SoundPool API to pause and resume all active streams. Bug 2426531.
Diffstat (limited to 'media/tests/SoundPoolTest')
-rw-r--r--media/tests/SoundPoolTest/src/com/android/SoundPoolTest.java45
1 files changed, 36 insertions, 9 deletions
diff --git a/media/tests/SoundPoolTest/src/com/android/SoundPoolTest.java b/media/tests/SoundPoolTest/src/com/android/SoundPoolTest.java
index 1434d3f..df1b375 100644
--- a/media/tests/SoundPoolTest/src/com/android/SoundPoolTest.java
+++ b/media/tests/SoundPoolTest/src/com/android/SoundPoolTest.java
@@ -52,7 +52,6 @@ public class SoundPoolTest extends Activity
R.raw.test5
};
- private final static int MAX_STREAMS = 1;
private final static float SEMITONE = 1.059463094f;
private final static float DEFAULT_VOLUME = 0.707f;
private final static float MAX_VOLUME = 1.0f;
@@ -70,6 +69,7 @@ public class SoundPoolTest extends Activity
private boolean mRunning;
private SoundPool mSoundPool = null;
private int mLastSample;
+ private int mMaxStreams;
private int mLoadStatus;
private int[] mSounds;
private float mScale[];
@@ -101,17 +101,18 @@ public class SoundPoolTest extends Activity
return id;
}
- private int initSoundPool() throws java.lang.InterruptedException {
+ private int initSoundPool(int numStreams) throws java.lang.InterruptedException {
if (mSoundPool != null) {
- if (mLoadStatus == 0) return mLoadStatus;
+ if ((mMaxStreams == numStreams) && (mLoadStatus == 0)) return mLoadStatus;
mSoundPool.release();
mSoundPool = null;
}
// create sound pool
mLoadStatus = 0;
- mSoundPool = new SoundPool(MAX_STREAMS, AudioSystem.STREAM_MUSIC, 0);
+ mMaxStreams = numStreams;
+ mSoundPool = new SoundPool(numStreams, AudioSystem.STREAM_MUSIC, 0);
mSoundPool.setOnLoadCompleteListener(new LoadCompleteCallback());
int numSounds = mTestFiles.length;
mSounds = new int[numSounds];
@@ -262,6 +263,31 @@ public class SoundPoolTest extends Activity
mSoundPool.stop(id);
+ // play 5 sounds, forces one to be stolen
+ int ids[] = new int[5];
+ for (int i = 0; i < 5; i++) {
+ ids[i] = mSoundPool.play(mSounds[0], DEFAULT_VOLUME, DEFAULT_VOLUME,
+ NORMAL_PRIORITY, DEFAULT_LOOP, mScale[i]);
+ if (DEBUG) Log.d(LOG_TAG, "Start note " + ids[i]);
+ if (ids[i] == 0) {
+ Log.e(LOG_TAG, "Error occurred starting note");
+ return false;
+ }
+ sleep(250);
+ }
+
+ // pause and resume sound a few times
+ for (int count = 0; count < 5; count++) {
+ mSoundPool.autoPause();
+ sleep(250);
+ mSoundPool.autoResume();
+ sleep(250);
+ }
+
+ for (int i = 0; i < 5; i++) {
+ mSoundPool.stop(ids[i]);
+ }
+
if (DEBUG) Log.d(LOG_TAG, "End pause/resume test");
return result;
}
@@ -309,17 +335,18 @@ public class SoundPoolTest extends Activity
try {
- // load sound pool
- initSoundPool();
-
- // do tests
+ // do single stream tests
+ initSoundPool(1);
if (!TestSounds()) failures = failures + 1;
if (!TestScales()) failures = failures + 1;
if (!TestRates()) failures = failures + 1;
if (!TestPriority()) failures = failures + 1;
- if (!TestPauseResume()) failures = failures + 1;
if (!TestVolume()) failures = failures + 1;
+ // do multiple stream tests
+ initSoundPool(4);
+ if (!TestPauseResume()) failures = failures + 1;
+
} catch (java.lang.InterruptedException e) {
if (DEBUG) Log.d(LOG_TAG, "Test interrupted");
failures = failures + 1;