当前位置: 首页>>代码示例>>Java>>正文


Java MediaRecorder.setOrientationHint方法代码示例

本文整理汇总了Java中android.media.MediaRecorder.setOrientationHint方法的典型用法代码示例。如果您正苦于以下问题:Java MediaRecorder.setOrientationHint方法的具体用法?Java MediaRecorder.setOrientationHint怎么用?Java MediaRecorder.setOrientationHint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaRecorder的用法示例。


在下文中一共展示了MediaRecorder.setOrientationHint方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: recordVideo

import android.media.MediaRecorder; //导入方法依赖的package包/类
public void recordVideo(VideoStartCallback videoStartCallback, VideoStopCallback videoStopCallback, VideoErrorCallback videoErrorCallback) {
    try {
        this.videoStartCallback = videoStartCallback;
        this.videoStopCallback = videoStopCallback;
        this.videoErrorCallback = videoErrorCallback;
        if(mCameraDevice == null || !mTextureView.isAvailable() || mPreviewSize == null){
            this.videoErrorCallback.onVideoError("Camera not ready.");
            return;
        }
        videoFile = Environment.getExternalStorageDirectory() + "/" + formatter.format(new Date()) + ".mp4";
        mMediaRecorder = new MediaRecorder();
        //mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
        mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mMediaRecorder.setOutputFile(videoFile);
        mMediaRecorder.setVideoEncodingBitRate(10000000);
        mMediaRecorder.setVideoFrameRate(30);
        mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
        mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
        //mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        if(swappedDimensions) {
            mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(mDisplayOrientation));
        } else {
            mMediaRecorder.setOrientationHint(ORIENTATIONS.get(mDisplayOrientation));
        }
        mMediaRecorder.prepare();
        closePreviewSession();
        createCameraRecordSession();
    } catch(IOException ex) {
        Log.d(TAG, ex.getMessage());
    }
}
 
开发者ID:EzequielAdrianM,项目名称:Camera2Vision,代码行数:33,代码来源:Camera2Source.java

示例2: configureRecorder

import android.media.MediaRecorder; //导入方法依赖的package包/类
protected void configureRecorder(int quality, MediaRecorder recorder) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraInfo.cameraId, info);
    int displayOrientation = getDisplayOrientation(info, false);
    recorder.setOrientationHint(displayOrientation);

    int highProfile = getHigh();
    boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
    boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
    if (canGoHigh && (quality == 1 || !canGoLow)) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
    } else if (canGoLow) {
        recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
    } else {
        throw new IllegalStateException("cannot find valid CamcorderProfile");
    }
    isVideo = true;
}
 
开发者ID:chengzichen,项目名称:KrGallery,代码行数:19,代码来源:CameraSession.java

示例3: initRecord

import android.media.MediaRecorder; //导入方法依赖的package包/类
private void initRecord() {
        try {
            mMediaRecorder = new MediaRecorder();
            mMediaRecorder.reset();
            mMediaRecorder.setCamera(mCamera);
            mMediaRecorder.setOnErrorListener(this);
            mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
            mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);//视频源
            mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);//音频源
            mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);//视频输出格式 也可设为3gp等其他格式
            mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);//音频格式
            mMediaRecorder.setVideoSize(mWidthPixel, mHeightPixel);//设置分辨率
//        mMediaRecorder.setVideoFrameRate(25);// 设置每秒帧数 这个设置有可能会出问题,有的手机不支持这种帧率就会录制失败,这里使用默认的帧率,当然视频的大小肯定会受影响
            if (mPictureSize < 3000000) {//这里设置可以调整清晰度
                mMediaRecorder.setVideoEncodingBitRate(3 * 1024 * 512);
            } else if (mPictureSize <= 5000000) {
                mMediaRecorder.setVideoEncodingBitRate(2 * 1024 * 512);
            } else {
                mMediaRecorder.setVideoEncodingBitRate(1 * 1024 * 512);
            }
            mMediaRecorder.setOrientationHint(90);//输出旋转90度,保持竖屏录制
            mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);//视频录制格式
            //mMediaRecorder.setMaxDuration(Constant.MAXVEDIOTIME * 1000);
            mMediaRecorder.setOutputFile(mRecordFile.getAbsolutePath());
            mMediaRecorder.prepare();
        } catch (Exception e) {
            e.printStackTrace();
            releaseCamera();
        }
    }
 
开发者ID:mChenys,项目名称:AndroidFFmpegCompress,代码行数:31,代码来源:RecordView.java

示例4: _startRecording

import android.media.MediaRecorder; //导入方法依赖的package包/类
private synchronized void _startRecording(Camera camera, String outPutFile, int rotationHint, int maxdurationMillis, CamcorderProfile profile)
{
    /**
     * IMPORTANT - Do not change the order of the steps in this function. Code
     * taken from the google camcoder sample
     *
     */

    Log.d(ImagingUtils.TAG, "start recording video");

    mIsRecording = true;

    // Step 1: Unlock and set camera to MediaRecorder
    mRecorder = new MediaRecorder();
    camera.unlock();

    mRecorder.setCamera(camera);


    // Step 2: Set sources
    mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);

    // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
    mRecorder.setProfile(profile);

    // Step 4: Set rotation and max duration

    //clckwise rotation for composition matrix as opposed to the 90degree anti-clockwise
    //rotation for the camera viewfinder
    //NOTE : This only works on some media players. Eg: works on VLC windows but not on VLC Linux
    mRecorder.setOrientationHint(rotationHint);
    mRecorder.setMaxDuration(maxdurationMillis + 1000);


    // Step 5 : set the file
    mRecorder.setOutputFile(outPutFile);

    // Step 6 : Prepare
    try
    {
        mRecorder.prepare();
    }
    catch (IOException e)
    {
        //Log.e("MediaRecorder prepare failed");
        e.printStackTrace();
    }
    mRecorder.start();
}
 
开发者ID:ravindu1024,项目名称:android-imaging-utils,代码行数:51,代码来源:VideoRecorder.java

示例5: prepareMediaRecorder

import android.media.MediaRecorder; //导入方法依赖的package包/类
private boolean prepareMediaRecorder() {
        try {
           // final Activity activity = getActivity();
            //if (null == activity) return false;
            //final BaseCaptureInterface captureInterface = (BaseCaptureInterface) activity;

           // setCameraDisplayOrientation(mCamera.getParameters());
            mMediaRecorder = new MediaRecorder();
            camera.stopPreview();
            camera.unlock();
            mMediaRecorder.setCamera(camera);

  //          boolean canUseAudio = true;
            //boolean audioEnabled = !mInterface.audioDisabled();
            //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            //    canUseAudio = ContextCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED;

//            if (canUseAudio && audioEnabled) {
                mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
//            } else if (audioEnabled) {
//                Toast.makeText(getActivity(), R.string.mcam_no_audio_access, Toast.LENGTH_LONG).show();
//            }
            mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

            final CamcorderProfile profile = CamcorderProfile.get(currentCameraId, CamcorderProfile.QUALITY_HIGH);
            mMediaRecorder.setOutputFormat(profile.fileFormat);
            mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
            mMediaRecorder.setVideoSize(previewSize.width, previewSize.height);
            mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
            mMediaRecorder.setVideoEncoder(profile.videoCodec);

            mMediaRecorder.setAudioEncodingBitRate(profile.audioBitRate);
            mMediaRecorder.setAudioChannels(profile.audioChannels);
            mMediaRecorder.setAudioSamplingRate(profile.audioSampleRate);
            mMediaRecorder.setAudioEncoder(profile.audioCodec);


            Uri uri = Uri.fromFile(FileUtils.makeTempFile(
                    new File(Environment.getExternalStorageDirectory(),
                            "/Omoshiroi/videos").getAbsolutePath(),
                    "VID_", ".mp4"));

            mMediaRecorder.setOutputFile(uri.getPath());

//            if (captureInterface.maxAllowedFileSize() > 0) {
//                mMediaRecorder.setMaxFileSize(captureInterface.maxAllowedFileSize());
//                mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
//                    @Override
//                    public void onInfo(MediaRecorder mediaRecorder, int what, int extra) {
//                        if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) {
//                            Toast.makeText(getActivity(), R.string.mcam_file_size_limit_reached, Toast.LENGTH_SHORT).show();
//                            stopRecordingVideo(false);
//                        }
//                    }
//                });
//            }

            mMediaRecorder.setOrientationHint(90);
     //       mMediaRecorder.setPreviewDisplay(mPreviewView.getHolder().getSurface());

            mMediaRecorder.prepare();
            return true;

        } catch (Exception e) {
            camera.lock();
            e.printStackTrace();
            return false;
        }
    }
 
开发者ID:zhangyaqiang,项目名称:Fatigue-Detection,代码行数:70,代码来源:CameraEngine.java


注:本文中的android.media.MediaRecorder.setOrientationHint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。