Android相机录制时间限制和最大尺寸

Posted

技术标签:

【中文标题】Android相机录制时间限制和最大尺寸【英文标题】:Android camera recording time limit and maximum size 【发布时间】:2016-11-03 09:36:25 【问题描述】:

如何设置 android 相机录制时间限制和最大尺寸。我已经尝试了很多意图和 mediaRecorder 两者。但没有人适合我。 这些问题有什么合适的解决方案吗?

日志

07-01 03:59:06.493 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@e15ffe8 time:15810029
07-01 03:59:09.346 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_launch_request id:com.enventpc_03.nav11 time:15812882
07-01 03:59:09.490 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_launch_request id:com.enventpc_03.nav11 time:15813026
07-01 03:59:09.917 16782-16782/com.enventpc_03.nav11 W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-01 03:59:10.126 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_launch_request id:com.enventpc_03.nav11 time:15813662
07-01 03:59:10.352 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_launch_request id:com.enventpc_03.nav11 time:15813888
07-01 03:59:10.387 16782-16809/com.enventpc_03.nav11 V/RenderScript: Application requested CPU execution
07-01 03:59:10.395 16782-16809/com.enventpc_03.nav11 V/RenderScript: 0x5592449c50 Launching thread(s), CPUs 4
07-01 03:59:11.068 16782-16782/com.enventpc_03.nav11 V/PhoneWindow: updateColorViewInt()if drawable=null color=-16777216
07-01 03:59:11.199 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@213dad01 time:15814735
07-01 03:59:11.199 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@1fb240d9 time:15814735
07-01 04:00:50.363 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@213dad01 time:15913899
07-01 04:00:55.746 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_launch_request id:com.enventpc_03.nav11 time:15919282
07-01 04:00:55.920 16782-16782/com.enventpc_03.nav11 V/PhoneWindow: updateColorViewInt()if drawable=null color=-16777216
07-01 04:00:56.173 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@158377d9 time:15919709
07-01 04:01:42.727 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_launch_request id:com.enventpc_03.nav11 time:15966263
07-01 04:01:42.925 16782-16782/com.enventpc_03.nav11 I/UploadApp: file path is null
07-01 04:01:43.323 16782-16782/com.enventpc_03.nav11 I/VideoView: Open Video
07-01 04:01:43.335 16782-16782/com.enventpc_03.nav11 E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
07-01 04:01:43.337 16782-16782/com.enventpc_03.nav11 I/VideoView: SetDataSource
07-01 04:01:43.339 16782-16782/com.enventpc_03.nav11 D/MediaPlayer: Couldn't open file on client side, trying server side
07-01 04:01:43.552 16782-16782/com.enventpc_03.nav11 D/MediaPlayer: getMetadata
07-01 04:01:43.839 16782-16782/com.enventpc_03.nav11 V/PhoneWindow: updateColorViewInt()if drawable=null color=-16777216
07-01 04:01:43.879 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@239081f2 time:15967415
07-01 04:01:43.879 16782-16782/com.enventpc_03.nav11 I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@158377d9 time:15967415
07-01 04:02:19.015 16782-16782/com.enventpc_03.nav11 I/VideoView: Playback Start begin
07-01 04:02:19.016 16782-16782/com.enventpc_03.nav11 I/VideoView: Playback Start end
07-01 04:02:19.035 16782-16782/com.enventpc_03.nav11 V/PhoneWindow: updateColorViewInt()else drawable=null color=-16777216

【问题讨论】:

【参考方案1】:

您只需使用MediaStore 属性传递intent 中的值。

    startActivityForResult(new Intent(MediaStore.ACTION_VIDEO_CAPTURE)
        .putExtra(android.provider.MediaStore.EXTRA_DURATION_LIMIT, 15) //15s Limit
        .putExtra(android.provider.MediaStore.EXTRA_SIZE_LIMIT, (5*1048*1048)+"L"), 0); //5MB Limit

【讨论】:

此代码不适用于大多数手机,例如联想,小米荣誉.. 您能发布一个日志以及您正在测试的版本吗?

以上是关于Android相机录制时间限制和最大尺寸的主要内容,如果未能解决你的问题,请参考以下文章

Android中的相机,如何获得最佳尺寸,预览尺寸,图片尺寸,视图尺寸,图像失真

在 Android 中,是不是可以更改相机(从前到后)并仍然继续录制?

在 Android 中,是不是可以更改相机(从前到后)并仍然继续录制?

Android相机 - 录制视频时预览放大

新浪微博gif图片最大有效显示尺寸是多少

Android 相机支持的图片尺寸