The intent was to provide a Camcorder view on an activity. For this, created an activity first and then in that a CamcorderView which shows the camera preview which can record on a tap action.
Camcorder view works with Android SurfaceView. The class declaration is something like below
public class CamcorderView extends SurfaceView implements SurfaceHolder.Callback
{
MediaRecorder recorder;
SurfaceHolder holder:
public CamcorderView (Context context, AttributeSet attrs)
{
holder = getHolder();
holder.addCallback(this);
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaREcorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recoder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
}
public void surfaceCreated(SurfaceHolder holder)
{
recorder.setOutputFile(outtputFile);
recorder.setPreviewDisplay(holder.getSurface());
if(recorder != null)
{
recorder.prepare();
}
}
public void startRecording()
{
recorder.start();
}
public void stopRecording()
{
recorder.stop();
recorder.release();
}
}
However, though the video and audio was captured without problem, when playing the recorded file, it was coming as green and now video was seen, however, audio was clear. Need to investigate the reason for this.
finally, found the bleow code to be working
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
CamcorderProfile cpHigh = CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
recorder.setOutputFile(outputFile);
recorder.setMaxDuration(500000); // 50 seconds
recorder.setMaxFileSize(10000000); // Approximately 5 megabytes
finally, found the bleow code to be working
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
CamcorderProfile cpHigh = CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
recorder.setOutputFile(outputFile);
recorder.setMaxDuration(500000); // 50 seconds
recorder.setMaxFileSize(10000000); // Approximately 5 megabytes
References
self
This video recording app is amazing! I have recently installed Total Recall recorder which has the supreme sound recording option and on acquiring this application now will avail you an offer price of 50 percent money off. Check more of its offers- https://play.google.com/store/apps/details?id=com.killermobile.totalrecall
ReplyDelete