MediaRecorder not working - android

i am using this code to record audio file in android device
private int output_formats[] = {MediaRecorder.OutputFormat.MPEG_4};
private String file_exts[] = {AUDIO_RECORDER_FILE_EXT_MP3};
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(output_formats[currentFormat]);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioEncodingBitRate(16);
recorder.setAudioSamplingRate(44100);
recorder.setOutputFile(getFilename());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
i am using 4.4.2 android device.
now my app is in both android as well as ios device so my recorded audio from 4.4.2 android device not working in ios device
how can i resolved this?
but this code working properly from other devices i checked using lollipop 5.0 or 6.0 android devices. all recorded audio working properly in ios device.
error in ios:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x7ca807b0 {Error Domain=NSOSStatusErrorDomain Code=-16170 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-16170)}

Related

Media recorder getting start falied in API level 27 (8.1.0)

I am working on records an audio. The following code works correctly until API level 25.
But when recording an audio, an exception media recorder start failed in pixel device (API level 27)(8.1.0) version.
Here is my code.
private void startRecording() {
recorder = new MediaRecorder();
if (Build.VERSION.SDK_INT <= 22) {
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
} else {
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
}
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilename());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Try to check if you have the permissions for recording: android.permission.RECORD_AUDIO
And make sure that the app has allowed that requested permission at runtime.

Recording script not working for Xiaomia for android App

We are try to records the call form our app its working fine for all other device except Xiaomi Note 3 and other MI devices . is any ways or setting need to change for run properly this below recording code in Xiaomi type device
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(fname);
try {
recorder.prepare();
recorder.start();
recording=true;
ts=getCurrentTS();
editor.putString("mdialerRecording", "true");editor.commit();
Toast.makeText(getApplicationContext(), "Recorder_Initialized1111 catch", Toast.LENGTH_LONG).show();
} catch (IllegalStateException e1) {
e1.printStackTrace();
File recfile = new File(fname);if(recfile.exists())recfile.delete();
} catch (IOException e1) {
e1.printStackTrace();
}

mediarecorder.audiosource.voice_call not working in xiaomi redmi error

I have tried to record call with AudioSource.VOICE_CALL in Android. It is working on most of devices like (Samsung S3 ,Samsung S4 , Nexus ) but in redmi xiaomi 1s it is not
Below is snippet of code that I used :
MediaRecorder recorder = new MediaRecorder();
recorder.reset();
recorder.setAudioSource(audiosource);
recorder.setOutputFormat(audioformat);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setOutputFile(recording.getAbsolutePath());
recorder.setOnInfoListener(this);
recorder.setOnErrorListener(this);
try {
recorder.prepare();
} catch (java.io.IOException e) {
recorder = null;
return;
}
recorder.start();

Increasing quality of recorded sound in android [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Improve Audio Recording quality in android?
I want to record audio to a 3gp file. I can do it without any problem and can hear the voice. But the voice i can hear is very slow and not clear. To increase voice quality i wrote a program but get java.lang.RuntimeException: start failed
public void onClick(View arg0)
{
root=Environment.getExternalStorageDirectory();
audiofile=new File(root,"sound.3gp");
if(!audiofile.exists())
{
Log.w(TAG, "File doesn't exists");
try
{
audiofile.createNewFile();
} catch (IOException e)
{
Log.w(TAG, "Unable to create audio file",e);
}
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setOutputFile(audiofile.getAbsolutePath());
try
{
recorder.setAudioSamplingRate(10);
recorder.setAudioEncodingBitRate(20);
recorder.prepare();
} catch (IllegalStateException e)
{
Log.w(TAG, "This is IllegalStateException");
} catch (IOException e)
{
Log.w(TAG, "This is IoException");
}
recorder.start();
}
what is wrong in my code? thanks.
As per my Existing Answer on Stackoverflow I provided you the below code to improve your sound quality.
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.getAudioSourceMax());
recorder.setAudioEncodingBitRate(16);
recorder.setAudioSamplingRate(44100);
recorder.setOutputFile(path);
recorder.prepare();
recorder.start();
i wrote a program but get java.lang.RuntimeException: start failed
Did u make sure at first run of your application you called in onStop
recorder.stop();
recorder.reset();
recorder.release();
I am pretty sure recorder is already in used when you are trying to run this program.thats why you are getting this error.always make sure you call above methods in onStop.Same goes true for Camera also.

android: record audio with MediaPlayer on emulator

I am trying to record audio from the microphone on the Android emulator with this code:
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(Environment.getExternalStorageDirectory() + "/test/test.3gp");
try {
recorder.prepare();
}
catch (IOException io) {
Log.v(LOG_TAG, "Could not prepare the audio " + io.getMessage());
}
recorder.start();
For stopping the audio, this is the code:
recorder.stop();
recorder.reset();
recorder.release();
The recording process works fine but the resulting audio that is distorted. When I record an audio for 60 seconds duration and play it, it's duration is being shown as 120 seconds. The measurement is not exact but the this is just to give you an idea.
Only the AMR_NB encoder is working on my emulator. I have tried different output formats but the result is always the same.
Is it a limitation of the emulator or am I doing something wrong here?
Edit 1:
I have tried the AudioRecord class too and the result is the same dragging audio.
Thanks.
I have been working for the same and found the solution, Try using the following code:
private void startRecording()
{
this.recorder = new MediaRecorder();
this.recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
this.recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
this.recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
MediaRecorder.getAudioSourceMax();
this.recorder.setOutputFile(this.getFilename());
this.recorder.setOnErrorListener(this.errorListener);
this.recorder.setOnInfoListener(this.infoListener);
try
{
this.recorder.prepare();
this.recorder.start();
} catch (final IllegalStateException e)
{
e.printStackTrace();
} catch (final IOException e)
{
e.printStackTrace();
}
}
This is working perfactly. Hope it helps you :)

Categories

Resources