我正在尝试限制将上传到服务器上的视频的持续时间。
我使用此代码让用户从图库中选择一个视频:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setType("video/*");
List<ResolveInfo> list = getPackageManager().queryIntentActivities(
intent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() <= 0) {
Log.d(TAG, "no video picker intent on this hardware");
return;
}
startActivityForResult(intent, GALLERY_RETURN);
如何为从图库中选择的视频设置1分钟的持续时间限制?
答案 0 :(得分:0)
Intent intent = new Intent();
intent.setAction(Intent.ACTION_PICK);
intent.setType("video/*");
List<ResolveInfo> list = getPackageManager().queryIntentActivities(
intent, PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() <= 0) {
Log.d(TAG, "no video picker intent on this hardware");
return;
}
long maxVideoSize = 24 * 1024 * 1024; // 10 MB
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, maxVideoSize);
startActivityForResult(intent, GALLERY_RETURN);
答案 1 :(得分:0)
mediaRecorder = new MediaRecorder();
mediaRecorder.setCamera(myCamera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
try {
mediaRecorder.setProfile(CamcorderProfile
.get(CamcorderProfile.QUALITY_480P));
} catch (Exception e) {
mediaRecorder.setProfile(CamcorderProfile
.get(CamcorderProfile.QUALITY_LOW));
}
mediaRecorder
.setOutputFile(Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
+ "/"
+ Config.IMAGE_DIRECTORY_NAME
+ "/TempVideo.mp4");
mediaRecorder.setMaxDuration(60000); // Set max duration 30 sec max of
// twitter.
// mediaRecorder.setMaxFileSize(14340032); // Set max file size ~ 7M
mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder()
.getSurface());
mediaRecorder.setOrientationHint(90);
mediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
public void onInfo(MediaRecorder mr, int what, int extra) {
if ((what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED)
|| (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED)) {
updateView();
}
}
});