下面列出了android.media.MediaRecorder#setAudioSamplingRate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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());
}
}
protected void initRecorder()
{
audioRecorder = new MediaRecorder();
audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
audioRecorder.setAudioEncodingBitRate(128000);
audioRecorder.setAudioSamplingRate(44100);
audioRecorder.setOutputFile(recordingPath);
audioRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
@Override
public void onInfo(MediaRecorder mediaRecorder, int i, int i1)
{
stopRecording();
}
});
}
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);
}
public void startRecording() {
setFileNameAndPath();
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setOutputFile(mFilePath);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setAudioChannels(1);
if (MySharedPreferences.getPrefHighQuality(this)) {
mRecorder.setAudioSamplingRate(44100);
mRecorder.setAudioEncodingBitRate(192000);
}
try {
mRecorder.prepare();
mRecorder.start();
mStartingTimeMillis = System.currentTimeMillis();
//startTimer();
//startForeground(1, createNotification());
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
}
private boolean startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setAudioEncodingBitRate(96000);
mRecorder.setAudioSamplingRate(22050);
setupOutputFile();
mRecorder.setOutputFile(mOutputFile.getAbsolutePath());
try {
mRecorder.prepare();
mRecorder.start();
mStartTime = SystemClock.elapsedRealtime();
mHandler.postDelayed(mTickExecutor, 100);
Log.d("Voice Recorder", "started recording to " + mOutputFile.getAbsolutePath());
return true;
} catch (Exception e) {
Log.e("Voice Recorder", "prepare() failed " + e.getMessage());
return false;
}
}
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);
}
}
}
private void startRecording() {
// 根据配置创建文件配置
GlobalSpec globalSpec = GlobalSpec.getInstance();
mAudioMediaStoreCompat = new MediaStoreCompat(getApplicationContext());
mAudioMediaStoreCompat.setSaveStrategy(globalSpec.audioStrategy == null ? globalSpec.saveStrategy : globalSpec.audioStrategy);
setFileNameAndPath();
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setOutputFile(mFile.getPath());
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setAudioChannels(1);
if (MySharedPreferences.getPrefHighQuality(this)) {
mRecorder.setAudioSamplingRate(44100);
mRecorder.setAudioEncodingBitRate(192000);
}
try {
mRecorder.prepare();
mRecorder.start();
mStartingTimeMillis = System.currentTimeMillis();
//startTimer();
//startForeground(1, createNotification());
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
}
protected void initRecorder()
{
recordingTimer = null;
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_RECOGNITION);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mediaRecorder.setAudioEncodingBitRate(128000);
mediaRecorder.setAudioSamplingRate(44100);
mediaRecorder.setOutputFile(recordedPath);
}
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);
}
}
public void onRecordClick(View v) {
if (!mRecording) {
File f = new File(getExternalFilesDir(null), "recording.mp4");
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setOutputFile(f.getAbsolutePath());
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC_ELD);
mRecorder.setAudioSamplingRate(48000);
mRecorder.setAudioEncodingBitRate(96000);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(TAG, "unable to prepare MediaRecorder");
mRecorder = null;
return;
}
mRecorder.start();
mRecording = true;
setState(STATE_RECORDING);
} else {
mRecorder.stop();
mRecorder.release();
mRecording = false;
setState(STATE_IDLE);
}
}
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());
}
private void promptSpeechInput() {
final MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioSamplingRate(8000);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setOutputFile(fileName);
try {
recorder.prepare();
} catch (IOException e) {
Toast.makeText(
getApplicationContext(),
"Failed to record audio",
Toast.LENGTH_SHORT).show();
return;
}
AlertDialog alertDialog = new AlertDialog.Builder(this)
.setMessage("Recording")
.setPositiveButton("Send", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
recorder.stop();
recorder.release();
sendAudio();
}
})
.create();
recorder.start();
alertDialog.show();
}
/**
* prepare for a new audio record.
*/
@WorkerThread
public synchronized boolean prepareRecord(int audioSource, int outputFormat, int audioEncoder,
int sampleRate, int bitRate, File outputFile) {
stopRecord();
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(audioSource);
mRecorder.setOutputFormat(outputFormat);
mRecorder.setAudioSamplingRate(sampleRate);
mRecorder.setAudioEncodingBitRate(bitRate);
mRecorder.setAudioEncoder(audioEncoder);
mRecorder.setOutputFile(outputFile.getAbsolutePath());
// Handle IOException
try {
mRecorder.prepare();
} catch (IOException exception) {
Log.w(TAG, "startRecord fail, prepare fail: " + exception.getMessage());
setError(ERROR_INTERNAL);
mRecorder.reset();
mRecorder.release();
mRecorder = null;
return false;
}
mState = STATE_PREPARED;
return true;
}
private boolean startRecording() {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
if (alternativeCodec) {
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
} else {
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setAudioEncodingBitRate(96000);
mRecorder.setAudioSamplingRate(22050);
}
setupOutputFile();
mRecorder.setOutputFile(mOutputFile.getAbsolutePath());
try {
mRecorder.prepare();
mRecorder.start();
mStartTime = SystemClock.elapsedRealtime();
mHandler.postDelayed(mTickExecutor, 100);
Log.d("Voice Recorder", "started recording to " + mOutputFile.getAbsolutePath());
return true;
} catch (Exception e) {
Log.e("Voice Recorder", "prepare() failed " + e.getMessage());
return false;
}
}
public MediaRecorder prepareMediaRecorder() {
audioRecorder = new MediaRecorder();
audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
audioRecorder.setAudioEncodingBitRate(256);
audioRecorder.setAudioChannels(1);
audioRecorder.setAudioSamplingRate(44100);
audioRecorder.setOutputFile(outputFile);
return audioRecorder;
}
@Override
protected void encodeWithMediaRecorder() throws IOException {
// We need a local socket to forward data output by the camera to the packetizer
createSockets();
Log.v(TAG,"Requested audio with "+mQuality.bitRate/1000+"kbps"+" at "+mQuality.samplingRate/1000+"kHz");
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setAudioSource(mAudioSource);
mMediaRecorder.setOutputFormat(mOutputFormat);
mMediaRecorder.setAudioEncoder(mAudioEncoder);
mMediaRecorder.setAudioChannels(1);
mMediaRecorder.setAudioSamplingRate(mQuality.samplingRate);
mMediaRecorder.setAudioEncodingBitRate(mQuality.bitRate);
// We write the output of the camera in a local socket instead of a file !
// This one little trick makes streaming feasible quiet simply: data from the camera
// can then be manipulated at the other end of the socket
FileDescriptor fd = null;
if (sPipeApi == PIPE_API_PFD) {
fd = mParcelWrite.getFileDescriptor();
} else {
fd = mSender.getFileDescriptor();
}
mMediaRecorder.setOutputFile(fd);
mMediaRecorder.setOutputFile(fd);
mMediaRecorder.prepare();
mMediaRecorder.start();
InputStream is = null;
if (sPipeApi == PIPE_API_PFD) {
is = new ParcelFileDescriptor.AutoCloseInputStream(mParcelRead);
} else {
try {
// mReceiver.getInputStream contains the data from the camera
is = mReceiver.getInputStream();
} catch (IOException e) {
stop();
throw new IOException("Something happened with the local sockets :/ Start failed !");
}
}
// the mPacketizer encapsulates this stream in an RTP stream and send it over the network
mPacketizer.setInputStream(is);
mPacketizer.start();
mStreaming = true;
}
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;
}
}
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;
}
public void Start(String filePath) throws Exception {
if (this.mRecordingState == RecordingState.STARTED) {
Log.w(TAG, "Already Recording");
return;
}
if (!TextUtils.isEmpty(filePath)) {
this.mFilePath = filePath;
}
attachView();
if (this.mRecordingState == RecordingState.INITIALIZING) {
this.mStartWhenInitialized = true;
return;
}
if (TextUtils.isEmpty(mFilePath)) {
throw new IllegalArgumentException("Filename for recording must be set");
}
initializeCamera();
if (mCamera == null) {
this.detachView();
throw new NullPointerException("Cannot start recording, we don't have a camera!");
}
// Set camera parameters
Camera.Parameters cameraParameters = mCamera.getParameters();
mCamera.stopPreview(); //Apparently helps with freezing issue on some Samsung devices.
mCamera.unlock();
try {
mRecorder = new MediaRecorder();
mRecorder.setCamera(mCamera);
CamcorderProfile profile;
if (CamcorderProfile.hasProfile(mCameraId, CamcorderProfile.QUALITY_LOW)) {
profile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_LOW);
} else {
profile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH);
}
Camera.Size lowestRes = CameraHelper.getLowestResolution(cameraParameters);
profile.videoFrameWidth = lowestRes.width;
profile.videoFrameHeight = lowestRes.height;
mRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
if (mRecordAudio) {
// With audio
mRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setVideoFrameRate(profile.videoFrameRate);
mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mRecorder.setAudioEncodingBitRate(profile.audioBitRate);
mRecorder.setAudioChannels(profile.audioChannels);
mRecorder.setAudioSamplingRate(profile.audioSampleRate);
mRecorder.setVideoEncoder(profile.videoCodec);
mRecorder.setAudioEncoder(profile.audioCodec);
} else {
// Without audio
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mRecorder.setVideoFrameRate(profile.videoFrameRate);
mRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mRecorder.setVideoEncoder(profile.videoCodec);
}
mRecorder.setOutputFile(filePath);
mRecorder.setOrientationHint(mOrientation);
mRecorder.prepare();
Log.d(TAG, "Starting recording");
mRecorder.start();
} catch (Exception e) {
this.releaseCamera();
Log.e(TAG, "Could not start recording! MediaRecorder Error", e);
throw e;
}
}
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);
}
}
}
}