我正在使用android.provider.MediaStore.ACTION_VIDEO_CAPTURE
。我想知道是否有办法改变每次录制所允许的最长时间。我试图添加 Intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60000);//max of 60 seconds
但它继续记录传递。提前致谢。是否可以使用intent设置允许的最大时间android记录?
回答
使用MediaRecorder
/**
* Starts a new recording.
*/
public void start() throws IOException {
recorder = new MediaRecorder();
String state = android.os.Environment.getExternalStorageState();
if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
throw new IOException("SD Card is not mounted. It is " + state
+ ".");
}
// make sure the directory we plan to store the recording in exists
File directory = new File(path).getParentFile();
System.out.println("start() directory > " + directory);
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Path to file could not be created.");
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC); // Sets the
// audio source
// to be used
// for recording
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // Sets
// the
// format
// of
// the
// output
// file
// produced
// during
// recording.
// 5 Minutes = 300000 Milliseconds
recorder.setMaxDuration(300000); // Sets the maximum duration (in ms) of
// the recording session
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); // Sets the
// audio
// encoder
// to be
// used for
// recording.
recorder.setOutputFile(path); // Sets the path of the output file to be
// produced.
recorder.prepare(); // Prepares the recorder to begin capturing and
// encoding data.
recorder.start(); // Recording is now started
}
谢谢詹妮弗,我曾尝试使用媒体录像机录制视频,但它在三星Galaxy等一些平台上不稳定。我希望有一种方法可以增加最大时间,因为我需要action_capture意图使用的所有内容。有任何想法吗? – user875139
你试过了:android.provider.MediaStore.EXTRA_DURATION_LIMIT对吗? – jennifer
是的,我试过这个intent.putExtra(“android.intent.extra.durationLimit”,60000);.依然没有。 – user875139
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra("android.intent.extra.durationLimit", 30000);
intent.putExtra("EXTRA_VIDEO_QUALITY", 0);
startActivityForResult(intent, ActivityRequests.REQUEST_TAKE_VIDEO);
此代码的工作以及对API 2.2,但持续时间限制不会对API 2.1
android.intent.extra.durationLimit
在API Level 8,
介绍所以它的工作不幸的是,在Eclair和更早的时候不可用。一些设备制造商可能会采用专有方式来设置旧设备的最长持续时间,这就解释了为什么您在某些Pre-Froyo应用程序中看到了这一点。
通过查看Android资源网站上灰色栏的右侧,您可以看到每个变量的API级别。例如,请参阅此变量(以及它的API级别):http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_DURATION_LIMIT – jennifer
请检查此链接:http://www.netmite.com /android/mydroid/donut/packages/apps/Camera/src/com/android/camera/VideoCamera.java ..它会对你有用 – jennifer
我在这里得到了错误的ActivityRequests? –
实际上,MediaStore.EXTRA_DURATION_LIMIT
提供的时间为秒,不是以毫秒为单位! 所以,你只需要改变你的价值从60000到60;) Android Documentation
使用此,这里60是第二 代码: intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60);
对于30秒的时间,试试这个代码。
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30);
- 1. 是否可以设置允许的最大ios版本
- 2. Android允许使用时间
- 3. 是否可以使用VisualStateManager设置控件的最大宽度
- 4. 记录集中允许的最大记录数?
- 5. 是否可以设置局部变量来允许任何值?
- 6. 的Android TimePickerDialog设置最大时间
- 7. Traceview最大记录时间?
- 8. Android:是否可以设置webView的缓存持续时间?
- 9. 是否可以配置Hibernate以允许多用途值?
- 10. 是否可以通过父母设置最大图像大小?
- 11. gimp是否允许您设置指南?
- 12. 设置允许的最大文件大小
- 13. 是否可以/允许使用具有标签标签的ID
- 14. 是否有MongoDB的最大记录数?
- 15. hadoop reducer的reduce()调用可以记录的最大记录数是多少?
- 16. 使用KVC设置不可访问的属性。这是否允许?
- 17. 是否可以让QFileDialog允许“仅文件”或“仅限目录”?
- 18. Python的imaplib是否允许您设置超时?
- 19. 是否可以从我的Android应用程序设置系统日期时间?
- 20. 是否可以使用swfObject设置cookie?
- 21. http基本认证 - 允许的最大试用时间?
- 22. Google存储对象是否可以设置为最大年龄?
- 23. 如何设置ACL以允许用户只访问特定的记录?
- 24. 是否可以手动调用警报“允许使用当前位置”?
- 25. 将PHP最大执行时间设置为600是否安全?
- 26. 是否可以使用nginx记录(但允许请求被执行)无效的引用者?
- 27. GtkSpinButton是否可以设置时间间隔?
- 28. 是否可以在FileSystemWatcher上设置时间间隔?
- 29. 是否可以在Android Webview中允许Flash Socket Client?
- 30. 设置java.net.URLConnection的最大超时时间
请注意MediaStore.EXTRA_DURATION_LIMIT是以秒为单位给出的,而不是毫秒。但它只适用于2.0后的设备。 – user953768