MediaRecorder启动失败:-16 [英] MediaRecorder start failed: -16

查看:186
本文介绍了MediaRecorder启动失败:-16的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道有很多解决方案在那里为MediaRecorder启动时的误差,但大多围绕着启动失败:-19,它已被链接到NO_INIT的查看所选答案评论这里。我还没有找到任何解决办法,或-16甚至一个解释。

So I realize there are many solutions out there for MediaRecorder start errors, however most of them revolve around "start failed: -19", which has been linked to "NO_INIT" See comments in selected answer here. I haven't found any solution, or even an explanation for -16.

如果有人知道在哪里可以找到这些错误codeS的名字,或有code的解决方案-16请把答案在这里!这里是code我使用。 (HTC霹雳,股吧)

If someone knows where i can find the names of these error codes, or has a solution for code -16 Please put the answer here!! Here is the code I'm using. (HTC Thunderbolt, Stock)

mr.setVideoSource(MediaRecorder.VideoSource.CAMERA); //mr is my mediaRecorder
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
mr.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mr.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mr.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mr.setOutputFile(ParcelFileDescriptor.fromSocket(soc).getFileDescriptor());  //soc is a java.net.ServerSocket pointing to a port on the device

mr.setVideoSize(480,800);
mr.setVideoFrameRate(5);
mr.prepare();
mr.start(); //Crashes with "start failed: -16"

logcat的

LOGCAT

07-11 10:14:34.879: V/MediaRecorderJNI(17939): JNIMediaRecorderListener::setCamera
07-11 10:14:34.879: V/MediaRecorderJNI(17939): process_media_recorder_call
07-11 10:14:47.549: V/MediaRecorderJNI(17939): setVideoSource(1)
07-11 10:14:47.549: V/MediaRecorderJNI(17939): getMediaRecorder E
07-11 10:14:47.559: V/MediaRecorderJNI(17939): process_media_recorder_call
07-11 10:14:47.559: V/MediaRecorderJNI(17939): setAudioSource(1)
07-11 10:14:47.559: V/MediaRecorderJNI(17939): getMediaRecorder E
07-11 10:14:47.559: V/MediaRecorderJNI(17939): process_media_recorder_call
07-11 10:14:47.559: V/MediaRecorderJNI(17939): setOutputFormat(0)
07-11 10:14:47.559: V/MediaRecorderJNI(17939): getMediaRecorder E
07-11 10:14:47.559: V/MediaRecorderJNI(17939): process_media_recorder_call
07-11 10:14:47.559: V/MediaRecorderJNI(17939): setVideoEncoder(0)
07-11 10:14:47.559: V/MediaRecorderJNI(17939): getMediaRecorder E
07-11 10:14:47.559: V/MediaRecorderJNI(17939): process_media_recorder_call
07-11 10:14:47.559: V/MediaRecorderJNI(17939): setAudioEncoder(0)
07-11 10:14:47.559: V/MediaRecorderJNI(17939): getMediaRecorder E
07-11 10:14:47.559: V/MediaRecorderJNI(17939): process_media_recorder_call
07-11 10:14:47.559: V/MediaRecorderJNI(17939): setVideoFrameRate(5)
07-11 10:14:47.559: V/MediaRecorderJNI(17939): getMediaRecorder E
07-11 10:14:47.559: V/MediaRecorderJNI(17939): process_media_recorder_call
07-11 10:14:47.559: V/MediaRecorderJNI(17939): setOutputFile
07-11 10:14:47.559: V/MediaRecorderJNI(17939): getMediaRecorder E
07-11 10:14:47.559: V/MediaRecorderJNI(17939): process_media_recorder_call
07-11 10:14:47.559: V/MediaRecorderJNI(17939): prepare
07-11 10:14:47.559: V/MediaRecorderJNI(17939): getMediaRecorder E
07-11 10:14:47.559: V/MediaRecorderJNI(17939): process_media_recorder_call
07-11 10:14:47.559: V/MediaRecorderJNI(17939): start
07-11 10:14:47.559: V/MediaRecorderJNI(17939): getMediaRecorder E
07-11 10:14:47.639: E/MediaRecorder(17939): start failed: -16
07-11 10:14:47.639: V/MediaRecorderJNI(17939): process_media_recorder_call
07-11 10:14:59.290: W/dalvikvm(17939): threadid=10: thread exiting with uncaught exception (group=0x4001d5a0)

更新12年7月11日下午2时21分:Discoverd的错误code -16实际上是-EBUSY。扩大LogCat中,包括了一切,彻底梳理的Andr​​oid源$ C ​​$ C之后,我发现它的相关的inablility调整(初始化)相机设置,我不知道我在做什么错了,但它的一个开始。如果你有机会获得AOSP你可以看到错误来自/frameworks/av/media/libstagefright/CameraSource.cpp CameraSource :: ConfigureCamera

UPDATE 07/11/12 2:21 PM: Discoverd the the error code -16 is actually -EBUSY. After expanding the LogCat to include everything, and combing thorough the Android source code, I found that its related to an inablility to adjust (initialize) the camera settings, I'm not sure what I'm doing wrong but its a start. If you have access to AOSP you can see that the error comes from /frameworks/av/media/libstagefright/CameraSource.cpp CameraSource::ConfigureCamera

推荐答案

我跑这个错误(-16开始),发现它是通过使用不支持分辨率造成的。

I ran in to this error (-16 on start) and found out it was caused by using an unsupported resolution.

首先,你必须从支持的尺寸得到最优尺寸

First you have to get the optimal size from the supported sizes

Parameters params = camera.getParameters();
        List<Size> sizes = params.getSupportedPreviewSizes();
        optimalSize = getOptimalPreviewSize(sizes, width, height);
params.setPreviewSize(optimalSize.width, optimalSize.height);

然后确保你同时设置preVIEW和视频相同的尺寸(如果他们在我的经验,preVIEW不同的,当录像开始将冻结):

Then make sure you set both preview and video to the same size (if they were different in my experience preview would freeze when video record started):

mediaRecorder.setVideoSize(optimalSize.width, optimalSize.height);

(样品code为getOptimal previewSize是Android SDK中)

(sample code for getOptimalPreviewSize is from android sdk)

private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
    final double ASPECT_TOLERANCE = 0.1;
    double targetRatio = (double) w / h;
    if (sizes == null) return null;

    Size optimalSize = null;
    double minDiff = Double.MAX_VALUE;

    int targetHeight = h;

    // Try to find an size match aspect ratio and size
    for (Size size : sizes) {
        double ratio = (double) size.width / size.height;
        if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE) continue;
        if (Math.abs(size.height - targetHeight) < minDiff) {
            optimalSize = size;
            minDiff = Math.abs(size.height - targetHeight);
        }
    }

    // Cannot find the one match the aspect ratio, ignore the requirement
    if (optimalSize == null) {
        minDiff = Double.MAX_VALUE;
        for (Size size : sizes) {
            if (Math.abs(size.height - targetHeight) < minDiff) {
                optimalSize = size;
                minDiff = Math.abs(size.height - targetHeight);
            }
        }
    }
    return optimalSize;
}  

这篇关于MediaRecorder启动失败:-16的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆