でビデオを録画しようとしていportrait orientation
ます。
カメラDisplayOrientation
を 90 度に設定すると、ビデオのプレビューが に表示されportrait
ます。
ただしsetOrientationHint()
、特定の番号(0、90、180、270)で呼び出すと、作成されたビデオは常に縦向きで作成されます。
Jellybean と ICS でテストしたところ、ビデオの向きはsetOrientationHint()
メソッドで設定したものでした。
MediaRecorder
初期化コードは次のとおりです。
private void initRecorder() {
Camera camera = Camera.open();
camera.setDisplayOrientation(90);
camera.unlock();
recorder.reset();
recorder.setCamera(camera);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
file = new File("/sdcard/test.mp4");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
recorder.setOrientationHint(90);//doesn't seem to work on 2.3
recorder.setOutputFile(file.getAbsolutePath());
recorder.setMaxDuration(30000);
recorder.setMaxFileSize(1000000);
}
そして、これは私が準備する場所ですMediaRecorder
:
public void surfaceCreated(SurfaceHolder holder) {
this.holder = holder;
recorder.setPreviewDisplay(holder.getSurface());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
finish();
} catch (IOException e) {
e.printStackTrace();
finish();
}
}
編集:
テスト済み:
Android 2.2 を実行している Samsung Galaxy S。
Android 2.3 を実行している Samsung Galaxy W。
ICSを実行しているSamsung galaxy S2 - 動作しました。
Jelly Bean を実行している Samsung galaxy s3 - 動作しました。