Android 4.0 bug with MediaRecorder - android

I have an application, which turns recording from mic when I have outgoing or incoming call on my phone...
mRecorder = new MediaRecorder();
mRecorder.reset();
// mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mRecorder.start();
It works on Android 2.xxx, now I have tryed to use it on HTC with android 4.0 and was surprised.... everything seems to work good.... But... recordings which were made are simply empty... At the beginning of it there is a sound for a second and then silence))) In LOG I have seen something like ...
09-19 14:10:36.462: INvAudioALSADevice(143): getMicMute state=F
09-19 14:10:36.462: INvAudioALSADevice(143): setMicMute state=F
I have found info about android interface on:
http://www.kandroid.org/online-pdk/guide/classandroid_1_1AudioHardwareInterface.html#_details
How can I win this BUG????

Related

android - Which MediaRecorder configuration is supported by all device?

I am recording communication voice in my app and I added storage and audio record permission manifest and also getting programmatically.
My code is working fine on one device(Android 6.0 Lenovo K3 Note)
But not on another (Android 8.1 ONEPLUS A5010)
In second device output is saved as a blank file of 3.15KB
I am adding my code which I am using please tell what I am doing wrong.
MediaRecorder mRecorder;
String mFileName;
Code in OnCreate
File file = new File(getFilesDir(), "engwingoLastCall.3gp");
mFileName = file.getAbsolutePath();
try {
if(mRecorder == null) {
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
}
} catch (Exception e) {
Log.d(TAG,"Recorder Error:"+e.getMessage());
}
Methods
public void startRecording() {
try {
if(mRecorder != null) {
mRecorder.prepare();
mRecorder.start();
}
} catch (Exception e) {
Log.d("Recorder", "prepare() failed");
}
}
public void stopRecording() {
if(mRecorder != null) {
try {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
} catch (IllegalStateException e) {
e.printStackTrace();
}catch (Exception e){
Log.d(TAG,e.getMessage());
}
}
}
Since you are not setting a profile with setProfile() method you may need to set audio channels, bitrate and sampling rate for audio too. Here is an example:
mRecorder.setAudioChannels(1);
// you would not want to record stereo, it is not logical
mRecorder.setAudioEncodingBitRate(128000);
// you can set it to 64000 or 96000 to lower quality, therefore decreasing the size of the audio
mRecorder.setAudioSamplingRate(44100);
// AFAIK, default value.
Hope this helps.
My Code was OK but the reason for this behavior of my recorder was,
Some other service also using my recorder at that time and that's why the file was saved empty (3.15KB Size)

How add effect to Media Recorder in android?

I Search everywhere i dont find anything.
how add effect on file audio in android?
This is my code...
mRecorder = new MediaRecorder();
mRecorder.setMaxDuration(180000);
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC);
mRecorder.setAudioEncodingBitRate(50000);
} else {
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mRecorder.setAudioEncodingBitRate(50000);
}
mRecorder.setAudioSamplingRate(50000);
mOutputFile = getOutputFile();
mOutputFile.getParentFile().mkdirs();
mRecorder.setOutputFile(mOutputFile.getAbsolutePath());
mRecorder.setAudioEncodingBitRate(50000);
mRecorder.setAudioSamplingRate(50000);
try {
mRecorder.prepare();
mRecorder.start();
mStartTime = SystemClock.elapsedRealtime();
mHandler.postDelayed(mTickExecutor, 100);
} catch (IOException e) {
}
Thank you very much if you help me!!!!!!
Solution : library called Sonic. Its basically for Speech as it use PSOLA algo to change pitch and tempo. But its ok.
by this library you can speeding up or slowing down speech and change the voice to child or woman or granny.

MediaRecorder not working

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)}

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();
}

Android MediaRecorder in streaming

Its possible to "stream" result of MediaRecorder?
The unique method i can see is mediaRecorder.setOutputFile that receives a FileDescriptor. So i can write the result to a File or send via socket to receiver.
I tried the second solution but the result video is corrupted because is not "seekable" in stream.
The idea is to use the camera of android device to publish result to Red5.
Yes, it possible, there are many examples for that.
You can checkout sipdroid example.
Or even Android IP camera which is much more simple.
Good Luck
Yes it is possible.
Here is the sample code with FileDescriptor and socket:
socket = new Socket("192.168.1.234",8888);
ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.fromSocket(socket);
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(fileDescriptor.getFileDescriptor);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "prepare() failed");
}
mRecorder.start();

Categories

Resources