如何在surfaceview视频录制中改变角度?

时间:2012-12-08 04:24:00

标签: android android-layout video surfaceview android-mediaplayer

我正在使用带有媒体记录器的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();
               }
           }

        }`

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分: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);**
           }