本文整理了Java中android.media.MediaRecorder
类的一些代码示例,展示了MediaRecorder
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MediaRecorder
类的具体详情如下:
包路径:android.media.MediaRecorder
类名称:MediaRecorder
暂无
代码示例来源:origin: stackoverflow.com
recorder = new MediaRecorder();
initRecorder();
setContentView(R.layout.main);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setProfile(cpHigh);
recorder.setOutputFile("/sdcard/videocapture_example.mp4");
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
recorder.stop();
recording = false;
} else {
recording = true;
recorder.start();
recorder.stop();
recording = false;
recorder.release();
代码示例来源:origin: stackoverflow.com
String out = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss").format(new Date());
File sampleDir = new File(Environment.getExternalStorageDirectory(), "/TestRecordingDasa1");
if (!sampleDir.exists()) {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
e.printStackTrace();
recorder.start();
recordstarted = true;
Toast.makeText(context, "REJECT || DISCO", Toast.LENGTH_LONG).show();
if (recordstarted) {
recorder.stop();
recordstarted = false;
代码示例来源:origin: stackoverflow.com
mediaRecorder = new MediaRecorder();
camera.unlock();
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mediaRecorder.setCamera(camera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setOutputFile(
Environment.getExternalStorageDirectory()+"/"+
DateFormat.format("yyyy-MM-dd_kk-mm-ss", new Date().getTime())+
".mp4"
);
try { mediaRecorder.prepare(); } catch (Exception e) {}
mediaRecorder.start();
public void onDestroy() {
mediaRecorder.stop();
mediaRecorder.reset();
mediaRecorder.release();
camera.lock();
camera.release();
代码示例来源:origin: ankidroid/Anki-Android
private MediaRecorder initMediaRecorder() {
MediaRecorder mr = new MediaRecorder();
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mStatus = Status.INITIALIZED;
mr.setOutputFile(mAudioPath); // audioPath
// could
// change
return mr;
}
};
代码示例来源:origin: florent37/CameraFragment
protected void releaseVideoRecorder() {
try {
if (videoRecorder != null) {
videoRecorder.reset();
videoRecorder.release();
}
} catch (Exception ignore) {
} finally {
videoRecorder = null;
}
}
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public void onStart() {
super.onStart();
recorder=new MediaRecorder();
recorder.setOnErrorListener(this);
recorder.setOnInfoListener(this);
}
代码示例来源:origin: stackoverflow.com
btnStarRecord.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Date date = new Date();
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setOutputFile(Environment.getExternalStorageDirectory() + "/myFolder" + "/" + dateFormat.format(date) + ".amr");
start(v);
}
});
代码示例来源:origin: huangfangyi/YiChat
public int stopRecoding() {
if(recorder != null){
isRecording = false;
recorder.stop();
recorder.release();
recorder = null;
if(file == null || !file.exists() || !file.isFile()){
return 401;
}
if (file.length() == 0) {
file.delete();
return 401;
}
int seconds = (int) (new Date().getTime() - startTime) / 1000;
// EMLog.d("voice", "voice recording finished. seconds:" + seconds + " file length:" + file.length());
return seconds;
}
return 0;
}
代码示例来源:origin: dongorigin/AndroidDemo
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String filename = "AUDIO_" + timestamp + ".aac";
mCurrentFile = new File(cacheDir, filename);
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
mMediaRecorder.setOutputFile(mCurrentFile.getAbsolutePath());
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mMediaRecorder.prepare();
mMediaRecorder.start();
mRecordStartTime = System.nanoTime();
isRecording = true;
代码示例来源:origin: stackoverflow.com
mMediaRecorder.start();
else {
mMediaRecorder.stop();
mMediaRecorder.reset();
try {
initRecorder(mHolder.getSurface());
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setPreviewDisplay(surface);
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mMediaRecorder.setOutputFile(this.initFile().getAbsolutePath());
mMediaRecorder.setMaxDuration(50000);
mMediaRecorder.setVideoFrameRate(24);
mMediaRecorder.setVideoSize(1280, 720);
mMediaRecorder.setVideoEncodingBitRate(3000000);
mMediaRecorder.setAudioEncodingBitRate(8000);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
代码示例来源:origin: stackoverflow.com
mMediaRecorder = new MediaRecorder();
mMediaRecorder.start();
mMediaRecorder.stop();
mMediaRecorder.reset();
mMediaRecorder.prepare();
} catch (Exception e) {
e.printStackTrace();
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(width, height);
mMediaRecorder.setOutputFile(filePath);
mVirtualDisplay = getVirtualDisplay();
mMediaRecorder.start();
width, height, screenDensity,
DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
mMediaRecorder.getSurface(), null /*Callbacks*/, null /*Handler*/);
代码示例来源:origin: huangfangyi/YiChat
private void startRecorder() {
try {
startRecorderInternal();
} catch (Exception e) {
Log.e(TAG, "start MediaRecord failed: " + e);
Toast.makeText(this, "录制失败...", Toast.LENGTH_SHORT).show();
mediaRecorder.release();
mediaRecorder = null;
camera.release();
camera = null;
return;
}
recording = true;
start = new Date().getTime();
handler.postDelayed(runnable, 1000);
recordingTimeTextView.setText("00:00");
updateRecordUI();
}
代码示例来源:origin: sxpl/FaceAC
this.mMediaRecorder = new MediaRecorder();
this.mMediaRecorder.reset();
if (this.mCamera != null) {
this.mMediaRecorder.setCamera(mCamera);
this.mMediaRecorder.setOnErrorListener(this);
this.mMediaRecorder.setPreviewDisplay(holder.getSurfaceHolder().getSurface());
this.mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);// 视频源
this.mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);// 音频源
this.mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);// 视频输出格式
this.mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);// 音频格式
this.mMediaRecorder.setVideoSize(PREVIEW_WIDTH, PREVIEW_HEIGHT);// 设置分辨率:
if (sizePicture < 3000000) {//这里设置可以调整清晰度
this.mMediaRecorder.setVideoEncodingBitRate(3 * 1024 * 512);
} else if (sizePicture <= 5000000) {
this.mMediaRecorder.setVideoEncodingBitRate(2 * 1024 * 512);
} else {
this.mMediaRecorder.setVideoEncodingBitRate(1 * 1024 * 512);
this.mMediaRecorder.setOrientationHint(270);// 输出旋转270度,保持竖屏录制
this.mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);// 视频录制格式
this.time = format.format(new Date());
this.outFile = new File(PATH + File.separator + FILE_NAME + time + FILE_NAME_SUFEIX);
this.mMediaRecorder.setOutputFile(outFile.getAbsolutePath());
this.mMediaRecorder.prepare();
try {
this.mMediaRecorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
代码示例来源:origin: EzequielAdrianM/Camera2Vision
return;
videoFile = Environment.getExternalStorageDirectory() + "/" + formatter.format(new Date()) + ".mp4";
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setOutputFile(videoFile);
mMediaRecorder.setVideoEncodingBitRate(10000000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(mDisplayOrientation));
} else {
mMediaRecorder.setOrientationHint(ORIENTATIONS.get(mDisplayOrientation));
mMediaRecorder.prepare();
closePreviewSession();
createCameraRecordSession();
代码示例来源:origin: stackoverflow.com
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile("/dev/null");
mRecorder.prepare();
mRecorder.start();
mRecorder.stop();
mRecorder.release();
mRecorder = null;
return mRecorder.getMaxAmplitude();
else
return 0;
代码示例来源:origin: stackoverflow.com
private SurfaceHolder surfaceHolder;
private SurfaceView surfaceView;
public MediaRecorder mrec = new MediaRecorder();
private Button startRecording = null;
String message = e.getMessage();
Log.i(null, "Problem Start"+message);
mrec.release();
mrec.stop();
mrec.release();
mrec = null;
break;
mrec = new MediaRecorder(); // Works well
mCamera.unlock();
mrec.setCamera(mCamera);
mrec.setPreviewDisplay(surfaceHolder.getSurface());
mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mrec.setAudioSource(MediaRecorder.AudioSource.MIC);
mrec.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mrec.setPreviewDisplay(surfaceHolder.getSurface());
mrec.setOutputFile("/sdcard/zzzz.3gp");
mrec.prepare();
mrec.start();
代码示例来源:origin: florent37/CameraFragment
@Override
protected boolean prepareVideoRecorder() {
videoRecorder = new MediaRecorder();
try {
camera.lock();
camera.unlock();
videoRecorder.setCamera(camera);
videoRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
videoRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
videoRecorder.setOutputFormat(camcorderProfile.fileFormat);
videoRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate);
videoRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
videoRecorder.setVideoEncodingBitRate(camcorderProfile.videoBitRate);
videoRecorder.setVideoEncoder(camcorderProfile.videoCodec);
videoRecorder.setAudioEncodingBitRate(camcorderProfile.audioBitRate);
videoRecorder.setAudioChannels(camcorderProfile.audioChannels);
videoRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate);
videoRecorder.setAudioEncoder(camcorderProfile.audioCodec);
videoRecorder.setOutputFile(outputPath.toString());
videoRecorder.setMaxFileSize(configurationProvider.getVideoFileSize());
videoRecorder.setOnInfoListener(this);
videoRecorder.setMaxDuration(configurationProvider.getVideoDuration());
代码示例来源:origin: stackoverflow.com
mediaRecorder = new MediaRecorder();
myCamera.unlock();
mediaRecorder.setCamera(myCamera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setOutputFile("/sdcard/myvideo1.mp4");
mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
mediaRecorder.setMaxFileSize(50000000); // Set max file size 50Mb
mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());
mediaRecorder.setOrientationHint(VideoWithSurfaceVw.orientation);
try {
mediaRecorder.prepare();
} catch (IllegalStateException e) {
releaseMediaRecorder();
mediaRecorder.reset(); // clear recorder configuration
mediaRecorder.release(); // release the recorder object
mediaRecorder = new MediaRecorder();
myCamera.lock(); // lock camera for later use
代码示例来源:origin: stackoverflow.com
setCameraParameters(camera);
camera.setPreviewDisplay(getHolder());
camera.unlock();
recorder = new MediaRecorder();
recorder.setCamera(camera);
setRecorderParameters(recorder);
recorder.prepare();
recorder.start();
Camera.Parameters param = camera.getParameters();
Pair<Integer, Integer> resolution = getResolution(getParams().quality);
param.setPreviewSize(resolution.first, resolution.second);
param.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
Pair<Integer, Integer> resolution = getResolution(getParams().quality);
profile.videoFrameWidth = resolution.first;
profile.videoFrameHeight = resolution.second;
recorder.setProfile(profile);
recorder.setOutputFile(file.getAbsolutePath());
recorder.setPreviewDisplay(getHolder().getSurface());
代码示例来源:origin: stackoverflow.com
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audioDirTemp + "/audio_file"
+ ".mp3");
recorder.setOnErrorListener(errorListener);
OnInfoListener infoListener = null;
recorder.setOnInfoListener(infoListener);
recorder.prepare();
recorder.start();
isRecording = true; // we are currently recording
} catch (IllegalStateException e) {
handler.removeCallbacks(updateVisualizer);
visualizerView.clear();
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
int x = recorder.getMaxAmplitude();
内容来源于网络,如有侵权,请联系作者删除!