setOrientationHint()什么都不做的姜饼,但工作在更高版本 [英] setOrientationHint() does nothing on Gingerbread, but works on later versions

查看:128
本文介绍了setOrientationHint()什么都不做的姜饼,但工作在更高版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想记录下纵向视频

相机 DisplayOrientation 设置为90度,使得preVIEW视频显示在人像

不过,当调用 setOrientationHint()与任何给定的数字(0,90,180,270)创建总是在纵向创建的视频。

当我已在杰利贝恩和ICS进行了测试,影像显示方向是一个我设置了 setOrientationHint()方法。

下面是 MediaRecorder 初始化code:

 私人无效initRecorder(){
    摄像头摄像头= Camera.open();
    camera.setDisplayOrientation(90);
    camera.unlock();
    recorder.reset();
    recorder.setCamera(照相机);
    recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setVideoEn codeR(MediaRecorder.VideoEn coder.MPEG_4_SP);
    recorder.setAudioEn codeR(MediaRecorder.AudioEn coder.DEFAULT);
    文件=新的文件(/ SD卡/ test.mp4);
    如果(!file.exists()){
        尝试 {
            file.createNewFile();
        }赶上(IOException异常E){
            e.printStackTrace();
        }
    }

    recorder.setOrientationHint(90); //似乎并没有工作在2.3

    recorder.setOutputFile(file.getAbsolutePath());
    recorder.setMaxDuration(30000);
    recorder.setMaxFileSize(1000000);
}
 

这是我的prepare的 MediaRecorder

 公共无效surfaceCreated(SurfaceHolder持有者){
    this.holder =持有人;
        recorder.set previewDisplay(holder.getSurface());
    尝试 {
        。录音机prepare();
    }赶上(IllegalStateException异常E){
        e.printStackTrace();
        完();
    }赶上(IOException异常E){
        e.printStackTrace();
        完();
    }
}
 

编辑:

测试上:

  1. 三星Galaxy S运行Android 2.2。

  2. 三星GalaxyW¯¯运行Android 2.3。

  3. 三星Galaxy S2运行ICS - 工作

  4. 三星galaxy S3运行果冻豆。 - 工作

解决方案

setOrientationHint()需要先 prepare被称为() 。检查是否发生这种情况。

另外请注意,这种方法只适用于 3GPP MPEG4 格式和一些视频播放器选择忽略此属性彻底。您正在使用的视频播放器可能会忽略它。

I am trying to record a video in portrait orientation.

Setting the Camera DisplayOrientation to 90 degrees makes the preview to video be displayed in portrait.

But When calling setOrientationHint() with any given number(0,90,180,270) the video that was created is created always in portrait orientation.

When I have tested it on Jellybean and on ICS, the video orientation was the one I set with the setOrientationHint() method.

Here is the MediaRecorder initialization code:

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);
}

And this is where I prepare the 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();
    }
}

EDIT:

Tested on:

  1. Samsung Galaxy S running android 2.2.

  2. Samsung Galaxy W running android 2.3.

  3. Samsung galaxy S2 running ICS - worked.

  4. Samsung galaxy s3 running Jelly Bean - worked.

解决方案

setOrientationHint() needs to be called before prepare(). Check if this is happening.

Also note that this method only works for 3gpp and mpeg4 formats and some video players choose to ignore this property completely. The video players you are using might be ignoring it.

这篇关于setOrientationHint()什么都不做的姜饼,但工作在更高版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆