List of usage examples for android.media MediaRecorder MEDIA_RECORDER_INFO_MAX_DURATION_REACHED
int MEDIA_RECORDER_INFO_MAX_DURATION_REACHED
To view the source code for android.media MediaRecorder MEDIA_RECORDER_INFO_MAX_DURATION_REACHED.
Click Source Link
From source file:freed.cam.apis.camera2.modules.VideoModuleApi2.java
@TargetApi(VERSION_CODES.LOLLIPOP) private void startPreviewVideo() { recordingFile = new File(cameraUiWrapper.getActivityInterface().getStorageHandler() .getNewFilePath(appSettingsManager.GetWriteExternal(), ".mp4")); mediaRecorder = new MediaRecorder(); mediaRecorder.reset();/*from w ww .j av a 2s. c om*/ mediaRecorder.setMaxFileSize(3037822976L); //~2.8 gigabyte mediaRecorder.setMaxDuration(7200000); //2hours mediaRecorder.setOnErrorListener(new OnErrorListener() { @Override public void onError(MediaRecorder mr, int what, int extra) { Log.d(TAG, "error MediaRecorder:" + what + "extra:" + extra); cameraUiWrapper.GetModuleHandler() .onRecorderstateChanged(I_RecorderStateChanged.STATUS_RECORDING_STOP); changeCaptureState(ModuleHandlerAbstract.CaptureStates.video_recording_stop); } }); mediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() { @Override public void onInfo(MediaRecorder mr, int what, int extra) { if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) { recordnextFile(mr); } else if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) { recordnextFile(mr); } } }); if (cameraUiWrapper.GetAppSettingsManager().getApiString(AppSettingsManager.SETTING_LOCATION) .equals(KEYS.ON)) { Location location = cameraUiWrapper.getActivityInterface().getLocationHandler().getCurrentLocation(); if (location != null) mediaRecorder.setLocation((float) location.getLatitude(), (float) location.getLongitude()); } switch (currentVideoProfile.Mode) { case Normal: case Highspeed: if (currentVideoProfile.isAudioActive) mediaRecorder.setAudioSource(AudioSource.CAMCORDER); break; case Timelapse: break; } mediaRecorder.setVideoSource(VideoSource.SURFACE); mediaRecorder.setOutputFormat(OutputFormat.MPEG_4); setRecorderFilePath(); mediaRecorder.setVideoEncodingBitRate(currentVideoProfile.videoBitRate); try { cameraHolder.SetParameterRepeating(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, new Range<>(currentVideoProfile.videoFrameRate, currentVideoProfile.videoFrameRate)); } catch (Exception e) { e.printStackTrace(); } // if(currentVideoProfile.Mode == VideoMediaProfile.VideoMode.SlowMO) // int SlowFactor = currentVideoProfile.videoFrameRate /30; if (currentVideoProfile.videoFrameRate == 120 && currentVideoProfile.videoFrameWidth == 1920) mediaRecorder.setVideoFrameRate(60); else mediaRecorder.setVideoFrameRate(currentVideoProfile.videoFrameRate); /*setCaptureRate Added in API level 11 void setCaptureRate (double fps) Set video frame capture rate. This can be used to set a different video frame capture rate than the recorded video's playback rate. !!!!!! This method also sets the recording mode to time lapse.!!!!! In time lapse video recording, only video is recorded. Audio related parameters are ignored when a time lapse recording session starts, if an application sets them.*/ //mediaRecorder.setCaptureRate((double)currentVideoProfile.videoFrameRate); mediaRecorder.setVideoSize(currentVideoProfile.videoFrameWidth, currentVideoProfile.videoFrameHeight); try { mediaRecorder.setVideoEncoder(currentVideoProfile.videoCodec); } catch (IllegalArgumentException ex) { mediaRecorder.reset(); cameraUiWrapper.GetCameraHolder().SendUIMessage("VideoCodec not Supported"); } switch (currentVideoProfile.Mode) { case Normal: case Highspeed: if (currentVideoProfile.isAudioActive) { try { mediaRecorder.setAudioEncoder(currentVideoProfile.audioCodec); } catch (IllegalArgumentException ex) { mediaRecorder.reset(); cameraUiWrapper.GetCameraHolder().SendUIMessage("AudioCodec not Supported"); } mediaRecorder.setAudioChannels(currentVideoProfile.audioChannels); mediaRecorder.setAudioEncodingBitRate(currentVideoProfile.audioBitRate); mediaRecorder.setAudioSamplingRate(currentVideoProfile.audioSampleRate); } break; case Timelapse: float frame = 30; if (!appSettingsManager.getApiString(AppSettingsManager.TIMELAPSEFRAME).equals("")) frame = Float.parseFloat( appSettingsManager.getApiString(AppSettingsManager.TIMELAPSEFRAME).replace(",", ".")); else appSettingsManager.setApiString(AppSettingsManager.TIMELAPSEFRAME, "" + frame); mediaRecorder.setCaptureRate(frame); break; } try { mediaRecorder.prepare(); } catch (IOException ex) { ex.printStackTrace(); cameraUiWrapper.GetModuleHandler().onRecorderstateChanged(I_RecorderStateChanged.STATUS_RECORDING_STOP); changeCaptureState(ModuleHandlerAbstract.CaptureStates.video_recording_stop); return; } recorderSurface = mediaRecorder.getSurface(); cameraHolder.CaptureSessionH.AddSurface(recorderSurface, true); if (currentVideoProfile.Mode != VideoMediaProfile.VideoMode.Highspeed) cameraHolder.CaptureSessionH.CreateCaptureSession(previewrdy); else cameraHolder.CaptureSessionH.CreateHighSpeedCaptureSession(previewrdy); }
From source file:freed.cam.apis.camera1.modules.AbstractVideoModule.java
@Override public void onInfo(MediaRecorder mr, int what, int extra) { if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) { recordnextFile(mr);//from ww w . ja v a2s . c o m } else if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) { recordnextFile(mr); } }
From source file:com.example.android.camera2basic.Camera2VideoFragment.java
private void setUpMediaRecorder() throws IOException { final Activity activity = getActivity(); if (null == activity) { return;// ww w . j a v a2 s .co m } mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() { @Override public void onInfo(MediaRecorder mr, int what, int extra) { if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) { Toast.makeText(getActivity(), "Video saved: " + mFile, Toast.LENGTH_SHORT).show(); CameraActivity activity = (CameraActivity) getActivity(); activity.setTake(true); activity.setOnListenAcc(true); Camera2BasicFragment fragment = activity.getCamerafragment(); activity.getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit(); } } }); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); //10 seconds mMediaRecorder.setMaxDuration(10000); mMediaRecorder.setOutputFile(getVideoFile(activity).getAbsolutePath()); mMediaRecorder.setVideoEncodingBitRate(10000000); mMediaRecorder.setVideoFrameRate(30); mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight()); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); int orientation = ORIENTATIONS.get(rotation); mMediaRecorder.setOrientationHint(orientation); mMediaRecorder.prepare(); }
From source file:com.example.zhang1ks.testbottombar.Camera2VideoFragment.java
private void startRecordingVideo() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return;//w ww .ja va 2 s . c o m } try { closePreviewSession(); setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder mRecorderSurface = mMediaRecorder.getSurface(); surfaces.add(mRecorderSurface); mPreviewBuilder.addTarget(mRecorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // UI mButtonVideo.setImageResource(R.drawable.stoprecording); mIsRecordingVideo = true; // Start recording mMediaRecorder.start(); } }); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } //Stop recording video automatically after timer reaches the max duration time. mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() { @Override public void onInfo(MediaRecorder mr, int what, int extra) { if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) { stopRecordingVideo(); } } }); }