android - Android Nexus 7 Jelly Bean:s​​tartPreview / takePicture调用getCameraStereoMode记录错误

我刚得到了一个nexus 7,我正在尝试将一些代码移植到。以下行适用于Xoom运行的冰淇淋:

mCamera.startPreview();

它在Nexus 7上也能正常工作,但会记录错误:
E/NvOmxCamera(  126): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoMode(NvxComponent*, NvOmxCameraUserStereoMode&): Error: invalid NVX mode 0.
E/NvOmxCamera(  126): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoModeAndCaptureInfo(NvxComponent*, NvOmxCameraUserStereoMode&, NVX_STEREOCAPTUREINFO&): getCameraStereoMode failed with 0x00000000

这是一个问题,因为当我执行行时,它还会每帧记录一次这些错误
mCamera.takePicture(null, null, null, pictureCallback);

因为我每秒拍摄10帧,这会干扰我,所以我想修正错误。我已经浏览了所有的源代码(android sdk和ndk),上面错误的文本不会出现在任何地方。我相信,从很多谷歌搜索,这是发生在Nvidia的openmax的实现,它似乎是与参数“nv立体声模式”,其中可能的值“左”,“右”,或“立体声”(nexus 7只有一个摄像头,所以我不知道为什么它会关心立体声摄像机A模式,但无论如何)。我尝试将其设置为每个合法值,例如:
mParams = mCamera.getParameters();
mParams.set("nv-stereo-mode", "right");
mCamera.setParameters(mParams);

但是,我的日志上说:
E/NvOmxCameraSettingsParser(  126): Skipping non-standard parameter: nv-stereo-mode

这似乎与源文件nvomxcamerasettingsParser.cpp有关,我在Web上的任何地方都找不到该文件。我真的不知道从这里到哪里去,我为我能想到的一切都在谷歌上搜索了一下,所以任何帮助都会受到极大的关注。


最佳答案:

请尝试以下代码解决您的问题。我希望它能正常工作。

import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class Record extends Activity implements SurfaceHolder.Callback,
    MediaRecorder.OnInfoListener {

Button myButton;
MediaRecorder mediaRecorder;
SurfaceHolder surfaceHolder;
boolean recording;
Camera camera;
int mCount;
TextView msg;
boolean rec = false;
String fileName = "DamageVideo.mp4";
CountDownTimer timer;

/** Called when the activity is first created. */
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    recording = false;

    mediaRecorder = new MediaRecorder(); 
    initMediaRecorder();

    setContentView(R.layout.record_view);

    SurfaceView myVideoView = (SurfaceView) findViewById(R.id.videoview);
    surfaceHolder = myVideoView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    myButton = (Button) findViewById(R.id.mybutton);
    msg = (TextView) findViewById(R.id.txttimer);

    myButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            myButton.setVisibility(View.GONE);
            myButton.setClickable(false);
            try {
                if (recording) {
                    recording = false;

                    myButton.setClickable(true);
                    myButton.setVisibility(View.VISIBLE);

                    Intent intent = new Intent();

                    setResult(100, intent);
                    finish();
                    overridePendingTransition(R.anim.trans_right_in,
                            R.anim.trans_right_out);

                    mediaRecorder.stop();
                    mediaRecorder.release();

                    moveFile();
                } else {

                    recording = true;
                    camera.stopPreview();
                    camera.release();
                    // myButton.setVisibility(View.GONE);
                    timer.start();
                    // myButton.setClickable(false);
                    mediaRecorder.start();

                    new CountDownTimer(21000, 1000) {

                        public void onTick(long millisUntilFinished) {

                            msg.setText(+(22000 - (millisUntilFinished - 0))
                                    / 1000 + "/20");

                        }

                        public void onFinish() {
                            // msg.setText("10/10");
                        }
                    }.start();
                    myButton.setText("STOP");
                    // camera.release();

                }
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
        }
    });

    timer = new CountDownTimer(1000, 1000) {

        public void onTick(long millisUntilFinished) {

        }

        public void onFinish() {
            myButton.setVisibility(View.VISIBLE);
            myButton.setClickable(true);
        }
    };

}

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

}

@Override
public void surfaceCreated(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

    try {
        prepareMediaRecorder();
        camera = Camera.open();

        try {
            camera.setPreviewDisplay(surfaceHolder);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        camera.startPreview();
    } catch (Exception e) {
        // TODO: handle exception
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

}

private void initMediaRecorder() {
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    CamcorderProfile camcorderProfile_HQ = CamcorderProfile
            .get(CamcorderProfile.QUALITY_HIGH);

    mediaRecorder.setProfile(camcorderProfile_HQ);
    // mediaRecorder.setVideoFrameRate(30);
    // File dir = Const.getFilePath();
    File dir = Environment.getExternalStorageDirectory();

    // String fname = "DamageVideo.mp4";

    mediaRecorder.setOutputFile(dir.getAbsolutePath() + "/" + fileName);
    mediaRecorder.setMaxDuration(20000); // Set max duration 60 sec.
    mediaRecorder.setOnInfoListener(this);
}

private void prepareMediaRecorder() {
    mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
    try {

        mediaRecorder.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
    // TODO Auto-generated method stub
    if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {

        // mr.stop();
        // mr.release();
        recording = false;

        mediaRecorder.stop();

        Intent intent = new Intent();

        setResult(100, intent);
        finish();
        overridePendingTransition(R.anim.trans_right_in,
                R.anim.trans_right_out);
        mediaRecorder.release();
        moveFile();
    }
}

@Override
public void onBackPressed() {

    super.onBackPressed();

    try {
        if (!recording) {
            File dir = Environment.getExternalStorageDirectory();
            File imgFile = new File(dir.getAbsolutePath(), fileName);
            if (imgFile.exists()) {
                imgFile.delete();
            }

            camera.stopPreview();
            camera.release();
        } else {
            mediaRecorder.stop();
            mediaRecorder.release();

            moveFile();
        }

        recording = false;

        Intent intent = new Intent();

        setResult(100, intent);
        finish();
        overridePendingTransition(R.anim.trans_right_in,
                R.anim.trans_right_out);
    } catch (Exception e) {
        // TODO: handle exception
    }

}

public void moveFile() {
    File temp = Environment.getExternalStorageDirectory();
    File from = new File(temp.getAbsolutePath(), fileName);

    File dir = Const.getFilePath(Record.this);
    File to = new File(dir.getAbsolutePath(), fileName);

    from.renameTo(to);
}

@Override
public void onResume() {
    super.onResume();

}
}

// xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<SurfaceView
    android:id="@+id/videoview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1" />

<Button
    android:id="@+id/mybutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="5dp"
    android:background="#55A5D8"
    android:padding="5dp"
    android:text="REC"
    android:textColor="#ffffff"
    android:textSize="20sp" />

<TextView
    android:id="@+id/txttimer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:text=""
    android:textColor="#55A5D8"
    android:textSize="20sp"
    android:textStyle="bold" />

</RelativeLayout>