Fix a test case failure when there is no back-facing camera on a device

Change-Id: I427b2e03b266ff2d92c6fe64f732a256d285020e
related-to-bug: 6538628
This commit is contained in:
James Dong
2012-05-30 20:35:03 -07:00
parent 7f6519691f
commit 7b996d19af

View File

@@ -415,59 +415,61 @@ public class MediaRecorderStressTest extends ActivityInstrumentationTestCase2<Me
output.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
try {
output.write("No of loop: ");
for (int i = 0; i < NUMBER_OF_TIME_LAPSE_LOOPS; i++) {
filename = OUTPUT_FILE + i + OUTPUT_FILE_EXT;
Log.v(TAG, filename);
runOnLooper(new Runnable() {
@Override
public void run() {
mRecorder = new MediaRecorder();
for (int j = 0, n = Camera.getNumberOfCameras(); j < n; j++) {
output.write("No of loop: camera " + j);
for (int i = 0; i < NUMBER_OF_TIME_LAPSE_LOOPS; i++) {
filename = OUTPUT_FILE + j + "_" + i + OUTPUT_FILE_EXT;
Log.v(TAG, filename);
runOnLooper(new Runnable() {
@Override
public void run() {
mRecorder = new MediaRecorder();
}
});
// Set callback
mRecorder.setOnErrorListener(mRecorderErrorCallback);
// Set video source
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Set camcorder profile for time lapse
CamcorderProfile profile =
CamcorderProfile.get(j, CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
mRecorder.setProfile(profile);
// Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc.
// http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
mRecorder.setCaptureRate(captureRate);
// Set output file
mRecorder.setOutputFile(filename);
// Set the preview display
Log.v(TAG, "mediaRecorder setPreviewDisplay");
mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mRecorder.prepare();
mRecorder.start();
Thread.sleep(record_duration);
Log.v(TAG, "Before stop");
mRecorder.stop();
mRecorder.release();
// Start the playback
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(filename);
mp.setDisplay(mSurfaceHolder);
mp.prepare();
mp.start();
Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
mp.release();
validateRecordedVideo(filename);
if (remove_video) {
removeRecordedVideo(filename);
}
});
// Set callback
mRecorder.setOnErrorListener(mRecorderErrorCallback);
// Set video source
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Set camcorder profile for time lapse
CamcorderProfile profile =
CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_HIGH);
mRecorder.setProfile(profile);
// Set the timelapse setting; 0.1 = 10 sec timelapse, 0.5 = 2 sec timelapse, etc.
// http://developer.android.com/guide/topics/media/camera.html#time-lapse-video
mRecorder.setCaptureRate(captureRate);
// Set output file
mRecorder.setOutputFile(filename);
// Set the preview display
Log.v(TAG, "mediaRecorder setPreviewDisplay");
mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mRecorder.prepare();
mRecorder.start();
Thread.sleep(record_duration);
Log.v(TAG, "Before stop");
mRecorder.stop();
mRecorder.release();
// Start the playback
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(filename);
mp.setDisplay(mSurfaceHolder);
mp.prepare();
mp.start();
Thread.sleep(TIME_LAPSE_PLAYBACK_WAIT_TIME);
mp.release();
validateRecordedVideo(filename);
if(remove_video) {
removeRecordedVideo(filename);
output.write(", " + i);
}
output.write(", " + i);
}
}
catch (IllegalStateException e) {