use of android.media.MediaRecorder in project cw-omnibus by commonsguy.
the class RecordingSession method start.
void start() {
recorder = new MediaRecorder();
recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoFrameRate(config.frameRate);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setVideoSize(config.width, config.height);
recorder.setVideoEncodingBitRate(config.bitRate);
recorder.setOutputFile(output.getAbsolutePath());
try {
recorder.prepare();
vdisplay = projection.createVirtualDisplay("andcorder", config.width, config.height, config.density, VIRT_DISPLAY_FLAGS, recorder.getSurface(), null, null);
beeper.startTone(ToneGenerator.TONE_PROP_ACK);
recorder.start();
} catch (IOException e) {
throw new RuntimeException("Exception preparing recorder", e);
}
}
use of android.media.MediaRecorder in project android_frameworks_base by ParanoidAndroid.
the class CodecTest method mediaRecorderRecord.
public static boolean mediaRecorderRecord(String filePath) {
Log.v(TAG, "SoundRecording - " + filePath);
//This test is only for the short media file
int duration = 0;
try {
MediaRecorder mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile(filePath);
mRecorder.prepare();
mRecorder.start();
Thread.sleep(500);
mRecorder.stop();
Log.v(TAG, "sound recorded");
mRecorder.release();
} catch (Exception e) {
Log.v(TAG, e.toString());
}
//Verify the recorded file
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(filePath);
mp.prepare();
duration = mp.getDuration();
Log.v(TAG, "Duration " + duration);
mp.release();
} catch (Exception e) {
}
//Check the record media file length is greate than zero
if (duration > 0)
return true;
else
return false;
}
use of android.media.MediaRecorder in project android_frameworks_base by ParanoidAndroid.
the class MediaRecorderTest method recordVideoWithPara.
private boolean recordVideoWithPara(VideoEncoderCap videoCap, AudioEncoderCap audioCap, boolean highQuality) {
boolean recordSuccess = false;
int videoEncoder = videoCap.mCodec;
int audioEncoder = audioCap.mCodec;
int videoWidth = highQuality ? videoCap.mMaxFrameWidth : videoCap.mMinFrameWidth;
int videoHeight = highQuality ? videoCap.mMaxFrameHeight : videoCap.mMinFrameHeight;
int videoFps = highQuality ? videoCap.mMaxFrameRate : videoCap.mMinFrameRate;
int videoBitrate = highQuality ? videoCap.mMaxBitRate : videoCap.mMinBitRate;
int audioBitrate = highQuality ? audioCap.mMaxBitRate : audioCap.mMinBitRate;
int audioChannels = highQuality ? audioCap.mMaxChannels : audioCap.mMinChannels;
int audioSamplingRate = highQuality ? audioCap.mMaxSampleRate : audioCap.mMinSampleRate;
//Overide the fps if the min_camera_fps is set
if (MediaFrameworkTestRunner.mMinCameraFps != 0 && MediaFrameworkTestRunner.mMinCameraFps > videoFps) {
videoFps = MediaFrameworkTestRunner.mMinCameraFps;
}
if (videoFps < MIN_VIDEO_FPS) {
videoFps = MIN_VIDEO_FPS;
}
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
String filename = ("/sdcard/" + videoEncoder + "_" + audioEncoder + "_" + highQuality + ".3gp");
try {
Log.v(TAG, "video encoder : " + videoEncoder);
Log.v(TAG, "audio encoder : " + audioEncoder);
Log.v(TAG, "quality : " + (highQuality ? "high" : "low"));
Log.v(TAG, "encoder : " + MediaProfileReader.getVideoCodecName(videoEncoder));
Log.v(TAG, "audio : " + MediaProfileReader.getAudioCodecName(audioEncoder));
Log.v(TAG, "videoWidth : " + videoWidth);
Log.v(TAG, "videoHeight : " + videoHeight);
Log.v(TAG, "videoFPS : " + videoFps);
Log.v(TAG, "videobitrate : " + videoBitrate);
Log.v(TAG, "audioBitrate : " + audioBitrate);
Log.v(TAG, "audioChannel : " + audioChannels);
Log.v(TAG, "AudioSampleRate : " + audioSamplingRate);
MediaRecorder mMediaRecorder = new MediaRecorder();
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mMediaRecorder.setOutputFile(filename);
mMediaRecorder.setVideoFrameRate(videoFps);
mMediaRecorder.setVideoSize(videoWidth, videoHeight);
mMediaRecorder.setVideoEncodingBitRate(videoBitrate);
mMediaRecorder.setAudioEncodingBitRate(audioBitrate);
mMediaRecorder.setAudioChannels(audioChannels);
mMediaRecorder.setAudioSamplingRate(audioSamplingRate);
mMediaRecorder.setVideoEncoder(videoEncoder);
mMediaRecorder.setAudioEncoder(audioEncoder);
mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mMediaRecorder.prepare();
mMediaRecorder.start();
Thread.sleep(MediaNames.RECORDED_TIME);
mMediaRecorder.stop();
mMediaRecorder.release();
recordSuccess = validateVideo(filename, videoWidth, videoHeight);
} catch (Exception e) {
Log.v(TAG, e.toString());
return false;
}
return recordSuccess;
}
use of android.media.MediaRecorder in project android_frameworks_base by ParanoidAndroid.
the class MediaRecorderTest method setUp.
protected void setUp() throws Exception {
getActivity();
mRecorder = new MediaRecorder();
super.setUp();
}
use of android.media.MediaRecorder in project android_frameworks_base by ParanoidAndroid.
the class MediaPlayerPerformance method stressVideoRecord.
// Note: This test is to assume the mediaserver's pid is 34
private boolean stressVideoRecord(int frameRate, int width, int height, int videoFormat, int outFormat, String outFile, boolean videoOnly) {
// Video recording
boolean doesTestFail = false;
for (int i = 0; i < NUM_PLAYBACk_IN_EACH_LOOP; i++) {
MediaRecorder mRecorder = new MediaRecorder();
try {
if (!videoOnly) {
Log.v(TAG, "setAudioSource");
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
}
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mRecorder.setOutputFormat(outFormat);
Log.v(TAG, "output format " + outFormat);
mRecorder.setOutputFile(outFile);
mRecorder.setVideoFrameRate(frameRate);
mRecorder.setVideoSize(width, height);
Log.v(TAG, "setEncoder");
mRecorder.setVideoEncoder(videoFormat);
if (!videoOnly) {
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
}
mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
mRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
mRecorder.prepare();
mRecorder.start();
Thread.sleep(MEDIA_STRESS_WAIT_TIME);
mRecorder.stop();
mRecorder.release();
} catch (Exception e) {
Log.v("record video failed ", e.toString());
mRecorder.release();
doesTestFail = true;
break;
}
}
return !doesTestFail;
}
Aggregations