use of android.media.MediaRecorder in project android_frameworks_base by ResurrectionRemix.
the class MediaRecorderStressTest method testStressTimeLapse.
// Test case for stressing time lapse
@LargeTest
public void testStressTimeLapse() throws Exception {
SurfaceHolder mSurfaceHolder;
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
int recordDuration = MediaRecorderStressTestRunner.mTimeLapseDuration;
boolean removeVideo = MediaRecorderStressTestRunner.mRemoveVideo;
double captureRate = MediaRecorderStressTestRunner.mCaptureRate;
Log.v(TAG, "Start camera time lapse stress:");
mOutput.write("Total number of loops: " + NUMBER_OF_TIME_LAPSE_LOOPS + "\n");
try {
for (int i = 0, n = Camera.getNumberOfCameras(); i < n; i++) {
mOutput.write("No of loop: camera " + i);
for (int j = 0; j < NUMBER_OF_TIME_LAPSE_LOOPS; j++) {
String fileName = String.format("%s/temp%d_%d%s", Environment.getExternalStorageDirectory(), i, j, 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(recordDuration);
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 (removeVideo) {
removeRecordedVideo(fileName);
}
if (j == 0) {
mOutput.write(j + 1);
} else {
mOutput.write(String.format(", %d", (j + 1)));
}
}
}
} catch (IllegalStateException e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test IllegalStateException");
} catch (IOException e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test IOException");
} catch (Exception e) {
Log.e(TAG, e.toString());
fail("Camera time lapse stress test Exception");
}
}
use of android.media.MediaRecorder in project CameraView by CJT2325.
the class CameraInterface method stopRecord.
void stopRecord(boolean isShort, StopRecordCallback callback) {
if (!isRecorder) {
return;
}
if (mediaRecorder != null && isRecorder) {
mediaRecorder.setOnErrorListener(null);
mediaRecorder.setOnInfoListener(null);
mediaRecorder.setPreviewDisplay(null);
try {
mediaRecorder.stop();
} catch (RuntimeException e) {
e.printStackTrace();
mediaRecorder = null;
mediaRecorder = new MediaRecorder();
Log.i("CJT", "stop RuntimeException");
} catch (Exception e) {
e.printStackTrace();
mediaRecorder = null;
mediaRecorder = new MediaRecorder();
Log.i("CJT", "stop Exception");
} finally {
mediaRecorder.release();
mediaRecorder = null;
isRecorder = false;
}
if (isShort) {
//delete video file
File file = new File(videoFileAbsPath);
if (file.exists()) {
file.delete();
}
callback.recordResult(null);
return;
}
doStopCamera();
String fileName = saveVideoPath + File.separator + videoFileName;
callback.recordResult(fileName);
}
}
use of android.media.MediaRecorder in project ChatKeyboard by CPPAlien.
the class AudioLib method start.
public synchronized void start(String path, OnAudioListener listener) {
LogUtil.d(TAG, "start recording");
mPeriod = 0;
mListener = listener;
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(path);
try {
recorder.prepare();
recorder.start();
updateMicStatus();
LogUtil.d(TAG, "record start success");
} catch (IllegalStateException e) {
e.printStackTrace();
LogUtil.e(TAG, "IllegalStateException");
} catch (IOException e) {
e.printStackTrace();
LogUtil.e(TAG, "IOException:" + e.getMessage());
}
mPath = path;
}
use of android.media.MediaRecorder in project Telecine by JakeWharton.
the class RecordingSession method startRecording.
private void startRecording() {
Timber.d("Starting screen recording...");
if (!outputRoot.exists() && !outputRoot.mkdirs()) {
Timber.e("Unable to create output directory '%s'.", outputRoot.getAbsolutePath());
Toast.makeText(context, "Unable to create output directory.\nCannot record screen.", LENGTH_SHORT).show();
return;
}
RecordingInfo recordingInfo = getRecordingInfo();
Timber.d("Recording: %s x %s @ %s", recordingInfo.width, recordingInfo.height, recordingInfo.density);
recorder = new MediaRecorder();
recorder.setVideoSource(SURFACE);
recorder.setOutputFormat(MPEG_4);
recorder.setVideoFrameRate(recordingInfo.frameRate);
recorder.setVideoEncoder(H264);
recorder.setVideoSize(recordingInfo.width, recordingInfo.height);
recorder.setVideoEncodingBitRate(8 * 1000 * 1000);
String outputName = fileFormat.format(new Date());
outputFile = new File(outputRoot, outputName).getAbsolutePath();
Timber.i("Output file '%s'.", outputFile);
recorder.setOutputFile(outputFile);
try {
recorder.prepare();
} catch (IOException e) {
throw new RuntimeException("Unable to prepare MediaRecorder.", e);
}
projection = projectionManager.getMediaProjection(resultCode, data);
Surface surface = recorder.getSurface();
display = projection.createVirtualDisplay(DISPLAY_NAME, recordingInfo.width, recordingInfo.height, recordingInfo.density, VIRTUAL_DISPLAY_FLAG_PRESENTATION, surface, null, null);
recorder.start();
running = true;
recordingStartNanos = System.nanoTime();
listener.onStart();
Timber.d("Screen recording started.");
analytics.send(//
new HitBuilders.EventBuilder().setCategory(Analytics.CATEGORY_RECORDING).setAction(Analytics.ACTION_RECORDING_START).build());
}
use of android.media.MediaRecorder in project SeaStar by 13120241790.
the class MediaRecorderUtils method startRecord.
private void startRecord() {
try {
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
File audioFile = new File(mFileName);
if (audioFile.exists()) {
audioFile.deleteOnExit();
}
mediaRecorder.setOutputFile(audioFile.getAbsolutePath());
mediaRecorder.prepare();
mediaRecorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations