How to limit audio recording time using Intent? - android

How can I limit recording when using intents?
I tried this code:
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra("android.intent.extra.durationLimit",5);
startActivityForResult(intent,RQS_RECORDING);
This code works fine when I record video. Time is countdown from 5 to 0 and after 5 seconds recording automatically stops. But this limited time does not work when I record sound. Why?
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
intent.putExtra("android.intent.extra.durationLimit", 5);
startActivityForResult(intent, RQS_RECORDING);
Why does this 5-second time limit not work when I record sound?

I Have a similar problem and I fixed my problem using below code snippet:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 5);
startActivityForResult(this, cameraIntent,CAMERA_PIC_REQUEST);
where CAMERA_PIC_REQUEST is my int type as:
private static final int CAMERA_PIC_REQUEST = 1337;

you should be try with MediaRecorder mRecorder = new MediaRecorder();
and mRecorder.setMaxDuration(5000) // 5 seconds;

private void recordVideo() {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
// set video quality
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set Video file
startActivityForResult(intent, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);
}
fileuri is your filepath. Try this.

intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 60);

Related

How to capture video in H265 codec in Android

I trying to write a test app in Android that captures video with camera. Looking at the recorded videos on my device, apparently it uses H264 AVC1 by default. I know my particualar device supports HEVC (Samsung S10). How can I change the code to record videos in H.265?
private void recordVideo() {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);
// set video quality
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the video file name
// start the video capture Intent
startActivityForResult(intent, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);
}

how to use SetMaxVideoDuration to record a video

how to use setmaxvideoDuration to record a video using camera-kit sdk?
You can set the duration limit code below.
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra("android.intent.extra.durationLimit", maxDurationMiliSecond);
startActivityForResult(intent, ActivityRequests.REQUEST_TAKE_VIDEO);

MediaStore.EXTRA_VIDEO_QUALITY not working for Android Video Capture

I am working on application where I am recording video from Camera Intent. On my Samsung mobile MediaStore.EXTRA_VIDEO_QUALITY is working and even my allocated memory size also works but same application on my Google Pixel there MediaStore.EXTRA_VIDEO_QUALITY is not working and even allocated size of memory is not working with camera intent.
My code is given below:
public void takeVideoFromCamera(){
File mediaFile =new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ "/myvideo.mp4");
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Uri videoUri;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// videoUri = FileProvider.getUriForFile(this, this.getApplicationContext().getPackageName() + ".provider", mediaFile);
videoUri = FileProvider.getUriForFile(this, "i.am.ce.by.murgqcy.provider", mediaFile);
} else {
videoUri = Uri.fromFile(mediaFile);
}
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, 5491520L);//5*1048*1048=5MB
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,45);
startActivityForResult(intent, VIDEO_CAPTURE);
}
According to MediaStore.EXTRA_VIDEO_QUALITY
You should change the value of MediaStore.EXTRA_VIDEO_QUALITY from 0 to 1.
0 means low quality
Thus could be the solution intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);

How to set video recording time limit and compress it to 2MB in android?

I am new to android, I am trying to develope an application which will record video for 10 seconds. This is my code.
public void startRecordingVideo() {
if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT)) {
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
mediaFile = new File(
Environment.getExternalStorageDirectory().getAbsolutePath() + "/video.mp4");
videoUri = Uri.fromFile(mediaFile);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
intent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
startActivityForResult(intent, VIDEO_CAPTURE);
} else {
Toast.makeText(this, "No camera on device", Toast.LENGTH_LONG).show();
}
}
I set in all possible ways, but I am not able to achieve my target. After attaining this, I need to compress this video to 2MB, I haven't start working on it because I stuck in capturing the video. Kindly help me. Thanks in advance.

Front-face in Android camera by default

I am using this code:
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
File photo = new File("/sdcard/picture.png");
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photo));
Uri imageUri = Uri.fromFile(photo);
startActivity(intent);
I would like to use this intent with a pre-defined setting, like front facing by default every time I fire the camera. Is that possible?
This is the front Camera intent, use it in your code!
here is an good tutorial: http://www.vogella.com/articles/AndroidCamera/article.html
int CAMERA_FACING_FRONT
Read more here: http://developer.android.com/reference/android/hardware/Camera.html

Categories

Resources