當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaRecorder.setCamera方法代碼示例

本文整理匯總了Java中android.media.MediaRecorder.setCamera方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaRecorder.setCamera方法的具體用法?Java MediaRecorder.setCamera怎麽用?Java MediaRecorder.setCamera使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.MediaRecorder的用法示例。


在下文中一共展示了MediaRecorder.setCamera方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Camera1Session

import android.media.MediaRecorder; //導入方法依賴的package包/類
private Camera1Session(Events events, boolean captureToTexture, Context applicationContext,
    SurfaceTextureHelper surfaceTextureHelper, MediaRecorder mediaRecorder, int cameraId,
    android.hardware.Camera camera, android.hardware.Camera.CameraInfo info,
    CaptureFormat captureFormat, long constructionTimeNs) {
  Logging.d(TAG, "Create new camera1 session on camera " + cameraId);

  this.cameraThreadHandler = new Handler();
  this.events = events;
  this.captureToTexture = captureToTexture;
  this.applicationContext = applicationContext;
  this.surfaceTextureHelper = surfaceTextureHelper;
  this.cameraId = cameraId;
  this.camera = camera;
  this.info = info;
  this.captureFormat = captureFormat;
  this.constructionTimeNs = constructionTimeNs;
  this.activityOrientation = getDeviceOrientation();

  startCapturing();

  if (mediaRecorder != null) {
    camera.unlock();
    mediaRecorder.setCamera(camera);
  }
}
 
開發者ID:Piasy,項目名稱:VideoCRE,代碼行數:26,代碼來源:Camera1Session.java

示例2: startRecorderInternal

import android.media.MediaRecorder; //導入方法依賴的package包/類
private boolean startRecorderInternal() throws Exception {
    shutdownCamera();
    if (!initCamera())
        return false;

    switchCamera.setVisibility(View.GONE);
    mediaRecorder = new MediaRecorder();

    camera.unlock();
    mediaRecorder.setCamera(camera);
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    setCamcorderProfile();

    mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
    mediaRecorder.setMaxDuration(1000 * VIDEO_TIMES);
    mediaRecorder.setOutputFile(filename);
    setVideoOrientation();

    mediaRecorder.prepare();
    mediaRecorder.start();

    return true;
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:26,代碼來源:CaptureVideoActivity.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: Camera1Session

import android.media.MediaRecorder; //導入方法依賴的package包/類
private Camera1Session(Events events, boolean captureToTexture, Context applicationContext,
    SurfaceTextureHelper surfaceTextureHelper, MediaRecorder mediaRecorder, int cameraId,
    android.hardware.Camera camera, android.hardware.Camera.CameraInfo info,
    CaptureFormat captureFormat, long constructionTimeNs) {
  Logging.d(TAG, "Create new camera1 session on camera " + cameraId);
  videoFrameEmitTrialEnabled =
      PeerConnectionFactory.fieldTrialsFindFullName(PeerConnectionFactory.VIDEO_FRAME_EMIT_TRIAL)
          .equals(PeerConnectionFactory.TRIAL_ENABLED);

  this.cameraThreadHandler = new Handler();
  this.events = events;
  this.captureToTexture = captureToTexture;
  this.applicationContext = applicationContext;
  this.surfaceTextureHelper = surfaceTextureHelper;
  this.cameraId = cameraId;
  this.camera = camera;
  this.info = info;
  this.captureFormat = captureFormat;
  this.constructionTimeNs = constructionTimeNs;

  startCapturing();

  if (mediaRecorder != null) {
    camera.unlock();
    mediaRecorder.setCamera(camera);
  }
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:28,代碼來源:Camera1Session.java

示例5: _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

示例6: 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.setCamera方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。