0

我正在使用surfaceview媒体录像机录制视频,它正在录制,但显示角度偏移了 90 度,这与实际的房间记录不同,也就是说,如果您使用我的应用程序录制房间,显示将偏移 90 度,房间天花板将在左侧,因此您的房间展示。任何人都可以帮助我解决这个问题以录制直角视频。这是我的代码供您参考,请在此处查看我的编码
main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="horizontal"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   >
<SurfaceView
  android:id="@+id/videoview" 
  android:layout_height="480px" android:layout_width="248dp"/>
<Button
  android:id="@+id/mybutton"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="REC"
  android:textSize="12dp"/> 
</RelativeLayout>` 

`
这是我的清单文件

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SurfaceAngleRecActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
</manifest>`  


`这是我的代码:

SurfaceAngleRecActivity.java                                        
public class SurfaceAngleRecActivity extends Activity implements SurfaceHolder.Callback
        {
        MediaRecorder mediaRecorder;
        SurfaceHolder surfaceHolder;
        boolean recording;
        Button record;
        MediaPlayer mediaPlayer;
    boolean pausing = false;

        String PlayPath ="/sdcard/myvideo.mp4";
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) 
       {
           super.onCreate(savedInstanceState);
           mediaRecorder = new MediaRecorder();
           initMediaRecorder();

           setContentView(R.layout.main);
           recording = false;


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

           record=(Button)findViewById(R.id.mybutton);

           record.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            if(!recording)
               {
                   mediaRecorder.start();
                   recording = true;
                   //Stop.setVisibility(View.VISIBLE);
                   //Record.setVisibility(View.INVISIBLE);
                   record.setText("STOP");
                   //Play.setEnabled(false);
                   //Pause.setEnabled(false);
               }else
               {
                   mediaRecorder.stop();
                   mediaRecorder.release();
                   recording = false;
                   //Record.setVisibility(View.VISIBLE);
                   //Stop.setVisibility(View.INVISIBLE);
                   //Record.setText("Record");
                   //Play.setEnabled(true);
                   //Pause.setEnabled(true);
                  // finish();
                   }
            }
        });

         }

        public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub

        }
        public void surfaceCreated(SurfaceHolder holder) {
            // TODO Auto-generated method stub
            prepareMediaRecorder();
        }
        public void surfaceDestroyed(SurfaceHolder holder) {
            // TODO Auto-generated method stub

        }
        private void initMediaRecorder()
           {
               mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
               mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
               //File file=new File(Environment.getExternalStorageDirectory(), PlayPath);
               CamcorderProfile camcorderProfile_HQ =CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
               mediaRecorder.setProfile(camcorderProfile_HQ);
               mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
               //mediaRecorder.setVideoSize(20, 20);
               //mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
           //mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M
           }

           private void prepareMediaRecorder()
           {
               mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
               try
               {
                   mediaRecorder.prepare();
                   //mediaRecorder.setVideoSize(150, 200);
               }
               catch (IllegalStateException e) 
               {
                   //TODO Auto-generated catch block
                   e.printStackTrace();
               }
               catch (IOException e) 
               {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
               }
           }

        }`
4

2 回答 2

0

在 Manifest 中将活动的方向更改为横向。

<application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".SurfaceAngleRecActivity" android:screenOrientation="landscape" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>

于 2013-05-21T09:37:14.470 回答
0
private void initMediaRecorder()
           {
               mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
               mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
               //File file=new File(Environment.getExternalStorageDirectory(), PlayPath);
               CamcorderProfile camcorderProfile_HQ =CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
               mediaRecorder.setProfile(camcorderProfile_HQ);
               mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
               **mediaRecorder.setOrientationHint(90);**
           }
于 2014-02-10T12:12:48.043 回答