31

我刚得到一个 Nexus 7,我正在尝试将一些代码移植到。以下行在运行 Ice Cream 的 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-stereo-mode”相关,该参数可能值为“left”、“right”或“stereo” (Nexus 7 只有一个摄像头,所以我不知道为什么它会关心立体摄像头模式,但无论如何)。我尝试将其设置为每个合法值,例如:

mParams = mCamera.getParameters();
mParams.set("nv-stereo-mode", "right");
mCamera.setParameters(mParams);

但是,我的日志说:

E/NvOmxCameraSettingsParser(  126): Skipping non-standard parameter: nv-stereo-mode

这似乎与源文件 nvomxcamerasettingsparser.cpp 有关,我在网络上的任何地方都找不到。我真的不知道从哪里开始,我已经搜索并搜索了我能想到的一切,所以任何帮助都会非常感激。

4

1 回答 1

1

试试下面的代码来解决你的问题。我希望它能正常工作。

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>
于 2014-11-24T06:30:35.230 回答