Methods Summary |
---|
private void | cleanupContentUriIfNecessary()
for (Uri uri : mContentUriMap.values()) {
getContentResolver().delete(uri, null, null);
}
mContentUriMap.clear();
|
public void | copyBetweenStreams(java.io.InputStream in, java.io.OutputStream out)
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
|
public abstract MediaPlayerProxy | createTestMediaPlayer()
|
private android.content.res.AssetManager | getAssets()
return getInstrumentation().getContext().getAssets();
|
private android.content.ContentResolver | getContentResolver()
return getInstrumentation().getContext().getContentResolver();
|
private android.net.Uri | getTestContentUri(java.lang.String assetFilename, java.lang.String assetMimeType)Gets the {@link Uri} for the test audio content we should play.
If this is the first time we've called this method, for a given file type and mime type, then
we'll have to insert some data into the content provider so that we can play it.
This is not thread safe, but doesn't need to be because all unit tests are executed from a
single thread, sequentially.
String key = keyFor(assetFilename, assetMimeType);
if (mContentUriMap.containsKey(key)) {
return mContentUriMap.get(key);
}
ContentValues values = new ContentValues();
values.put(VoicemailContract.Voicemails.DATE, String.valueOf(System.currentTimeMillis()));
values.put(VoicemailContract.Voicemails.NUMBER, CONTACT_NUMBER);
values.put(VoicemailContract.Voicemails.MIME_TYPE, assetMimeType);
String packageName = getInstrumentation().getTargetContext().getPackageName();
Uri uri = getContentResolver().insert(
VoicemailContract.Voicemails.buildSourceUri(packageName), values);
AssetManager assets = getAssets();
OutputStream outputStream = null;
InputStream inputStream = null;
try {
inputStream = assets.open(assetFilename);
outputStream = getContentResolver().openOutputStream(uri);
copyBetweenStreams(inputStream, outputStream);
mContentUriMap.put(key, uri);
return uri;
} finally {
Closeables.closeQuietly(outputStream);
Closeables.closeQuietly(inputStream);
}
|
private java.lang.String | keyFor(java.lang.String assetFilename, java.lang.String assetMimeType)
return assetFilename + "+" + assetMimeType;
|
protected void | runTest()
// Tests annotated with ShouldThrowIllegalStateException will fail if they don't.
// Tests not annotated this way are run as normal.
if (getClass().getMethod(getName()).isAnnotationPresent(
ShouldThrowIllegalStateException.class)) {
try {
super.runTest();
fail("Expected this method to throw an IllegalStateException, but it didn't");
} catch (IllegalStateException e) {
// Expected.
}
} else {
super.runTest();
}
|
private void | setDataSourceFromContentProvider(MediaPlayerProxy player, java.lang.String assetFilename, java.lang.String assetMimeType)
player.setDataSource(getInstrumentation().getTargetContext(),
getTestContentUri(assetFilename, assetMimeType));
|
protected void | setUp()
super.setUp();
mPlayer = createTestMediaPlayer();
mCompletionListener = new AwaitableCompletionListener();
mErrorListener = new AwaitableErrorListener();
|
private void | setVariableSpeedRateIfSupported(float rate)If we have a variable speed media player proxy, set the variable speed rate.
If we don't have a variable speed media player proxy, this method will be a no-op.
if (mPlayer instanceof SingleThreadedMediaPlayerProxy) {
((SingleThreadedMediaPlayerProxy) mPlayer).setVariableSpeed(rate);
} else if (mPlayer instanceof VariableSpeed) {
((VariableSpeed) mPlayer).setVariableSpeed(rate);
}
|
protected void | tearDown()
mCompletionListener = null;
mErrorListener = null;
mPlayer.release();
mPlayer = null;
cleanupContentUriIfNecessary();
super.tearDown();
|
public void | testDoubleStartWaitingForFinish()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
|
public void | testFinishPlayingThenSeekToHalfWayThenPlayAgain()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
mPlayer.seekTo(mPlayer.getDuration() / 2);
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
|
public void | testGetCurrentPosition_DuringPlayback()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.start();
Thread.sleep(2000);
assertEquals(2000, mPlayer.getCurrentPosition(), ERROR_TOLERANCE_MILLIS);
|
public void | testGetCurrentPosition_DuringPlaybackWithSeek()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.seekTo(1500);
mPlayer.start();
Thread.sleep(1500);
assertEquals(3000, mPlayer.getCurrentPosition(), ERROR_TOLERANCE_MILLIS);
|
public void | testGetCurrentPosition_FinishedPlaying()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
assertEquals(mPlayer.getDuration(), mPlayer.getCurrentPosition(), ERROR_TOLERANCE_MILLIS);
|
public void | testGetCurrentPosition_ZeroBeforePlaybackBegins()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
assertEquals(0, mPlayer.getCurrentPosition());
mPlayer.prepare();
assertEquals(0, mPlayer.getCurrentPosition());
|
public void | testGetDuration()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
int duration = mPlayer.getDuration();
assertTrue("duration was " + duration, duration > 0);
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
assertEquals(duration, mPlayer.getDuration());
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
assertEquals(duration, mPlayer.getDuration());
|
public void | testGetDurationAfterRelease_ShouldFail()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.release();
mPlayer.getDuration();
|
public void | testGetPositionAfterRelease_ShouldFail()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.release();
mPlayer.getCurrentPosition();
|
public void | testHalfWaySeekWithStutteringAudio()
// The audio contained in this file has a stutter if we seek to half way and play.
// It shouldn't have.
setDataSourceFromContentProvider(mPlayer, "fake_voicemail2.mp3", "audio/mp3");
mPlayer.prepare();
assertTrue(mPlayer.getDuration() > 0);
mPlayer.seekTo(mPlayer.getDuration() / 2);
mPlayer.start();
mPlayer.setOnCompletionListener(mCompletionListener);
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
|
public void | testIllegalPreparingDoesntFireErrorListener()
mPlayer.setOnErrorListener(mErrorListener);
try {
mPlayer.prepare();
fail("This should have thrown an IllegalStateException");
} catch (IllegalStateException e) {
// Good, expected.
}
mErrorListener.assertNoMoreCallbacks();
|
public void | testPause_DoesNotInvokeCallback()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mPlayer.pause();
Thread.sleep(200);
mCompletionListener.assertNoMoreCallbacks();
|
public void | testPause_DuringPlayback()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.start();
assertTrue(mPlayer.isPlaying());
Thread.sleep(2000);
assertTrue(mPlayer.isPlaying());
mPlayer.pause();
assertFalse(mPlayer.isPlaying());
|
public void | testPause_MultipleTimes()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.start();
Thread.sleep(2000);
mPlayer.pause();
mPlayer.pause();
|
public void | testPlayABitThenRelease()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.start();
Thread.sleep(2000);
|
public void | testPlayFully()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
|
public void | testPlaySingleChannelLowSampleRate3gppFile()
setDataSourceFromContentProvider(mPlayer, "count_and_test.3gpp", "audio/3gpp");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
|
public void | testPlayTwoDifferentTypesWithSameMediaPlayer()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
mPlayer.reset();
setDataSourceFromContentProvider(mPlayer, "count_and_test.3gpp", "audio/3gpp");
mPlayer.prepare();
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
|
public void | testPrepare()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
|
public void | testPrepareBeforeSetDataSource_ShouldFail()
mPlayer.prepare();
|
public void | testPrepareTwice_ShouldFailWithIllegalState()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.prepare();
|
public void | testReleaseMultipleTimesHasNoEffect()
mPlayer.release();
mPlayer.release();
|
public void | testRepeatedlySeekingDuringPlayback()
// Start playback then seek repeatedly during playback to the same point.
// The real media player should play a stuttering audio, hopefully my player does too.
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
Thread.sleep(500);
for (int i = 0; i < 40; ++i) {
Thread.sleep(200);
mPlayer.seekTo(2000);
}
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
|
public void | testRepeatedlySeekingDuringPlaybackRandomAndVeryFast()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
Thread.sleep(500);
for (int i = 0; i < 40; ++i) {
Thread.sleep(250);
mPlayer.seekTo(1500 + (int) (Math.random() * 1000));
}
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
|
public void | testResetAfterPlaybackThenReUse()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.prepare();
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
mPlayer.reset();
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.start();
Thread.sleep(2000);
|
public void | testResetDuringPlaybackThenReUse()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.start();
Thread.sleep(2000);
mPlayer.reset();
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.start();
Thread.sleep(2000);
|
public void | testResetOnNewlyCreatedObject()
mPlayer.reset();
|
public void | testResetWithoutReleaseAndThenReUse()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.reset();
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.seekTo(mPlayer.getDuration() / 2);
mPlayer.start();
Thread.sleep(1000);
|
public void | testReset_DoesNotInvokeCallback()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mPlayer.reset();
Thread.sleep(200);
mCompletionListener.assertNoMoreCallbacks();
|
public void | testSeekDuringPlayback()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
Thread.sleep(2000);
mPlayer.seekTo(0);
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
Thread.sleep(200);
mCompletionListener.assertNoMoreCallbacks();
|
public void | testSeekHalfWayBeforePlaying()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
assertTrue(mPlayer.getDuration() > 0);
mPlayer.seekTo(mPlayer.getDuration() / 2);
mPlayer.start();
mPlayer.setOnCompletionListener(mCompletionListener);
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
|
public void | testSeekToEndThenPlayThenRateChangeCrash()
// Unit test for this bug: http://b/5140693
// This test proves that the bug is fixed.
setDataSourceFromContentProvider(mPlayer, "fake_voicemail.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.seekTo(mPlayer.getDuration() - 1);
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
// Prior to the fix, this next line was causing a crash.
// The reason behind this was due to our having seeked so close to the end of the file
// that insufficient data was being read, and thus we weren't able to yet determine the
// sample rate and number of channels, which was causing an assertion failure when trying
// to create the time scaler.
setVariableSpeedRateIfSupported(1.0f);
|
public void | testSetDataSource()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
|
public void | testSetDataSourceAfterRelease_ShouldFailWithIllegalState()
mPlayer.release();
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
|
public void | testSetDataSourceForMissingFile_ThrowsIOExceptionInPrepare()
mPlayer.setOnErrorListener(mErrorListener);
mPlayer.setDataSource("/this/file/does/not/exist/");
try {
mPlayer.prepare();
fail("Should have thrown IOException");
} catch (IOException e) {
// Good, expected.
}
// Synchronous prepare does not report errors to the error listener.
mErrorListener.assertNoMoreCallbacks();
|
public void | testSetDataSourceTwice_ShouldFailWithIllegalState()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
|
public void | testStartThenImmediatelyRelease()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.start();
|
public void | testThreeFastConsecutiveStarts()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mPlayer.start();
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
Thread.sleep(4000);
mCompletionListener.assertNoMoreCallbacks();
|
public void | testTwoFastConsecutiveStarts()
setDataSourceFromContentProvider(mPlayer, "quick_test_recording.mp3", "audio/mp3");
mPlayer.prepare();
mPlayer.setOnCompletionListener(mCompletionListener);
mPlayer.start();
mPlayer.start();
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
Thread.sleep(200);
mCompletionListener.assertNoMoreCallbacks();
|
public void | testVariableSpeedRateChangeAtDifferentTimes()
// Just check that we can set the rate at any point during playback.
setVariableSpeedRateIfSupported(1.05f);
setDataSourceFromContentProvider(mPlayer, "fake_voicemail.mp3", "audio/mp3");
setVariableSpeedRateIfSupported(1.10f);
mPlayer.prepare();
setVariableSpeedRateIfSupported(1.15f);
mPlayer.seekTo(mPlayer.getDuration() / 2);
setVariableSpeedRateIfSupported(1.20f);
mPlayer.setOnCompletionListener(mCompletionListener);
setVariableSpeedRateIfSupported(1.25f);
mPlayer.start();
setVariableSpeedRateIfSupported(1.30f);
mCompletionListener.awaitOneCallback(10, TimeUnit.SECONDS);
setVariableSpeedRateIfSupported(1.35f);
|