setDataSource Failed
yumweb opened this issue · 8 comments
Hi Kevin,
Thanks for this module. It has been quite easier to use than the other libraries. Although, I have been facing some issues when recording using options on Android. I am not sure if this issue is specific to me or a bug in general. Recording works perfectly fine if no options are passed; but when any options are passed the app throws an error.
Below is the code that I am trying to use passing the additional source
and format
options. With the source set to SoundRecorder.VOICE_CALL
I am basically trying to record the call conversation.
if (data.callState == 0) {
SoundRecorder.start('/storage/emulated/0/Music/test.mp4', {
source: SoundRecorder.VOICE_CALL,
format: SoundRecorder.FORMAT_MPEG_4
})
.then(function() {
console.log('started recording');
});
} else if (data.callState !== 1) {
SoundRecorder.stop()
.then(function(path) {
console.log('stopped recording, audio file saved at: ' + JSON.stringify(path));
});
}
I get the following error at the time of stopping the recording. A corrupted file is saved to the location specified.
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: Exception in native call
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at android.media.MediaMetadataRetriever.setDataSource(Native Method)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:80)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at com.reactlibrary.RNSoundRecorderModule.stop(RNSoundRecorderModule.java:146)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at java.lang.reflect.Method.invoke(Native Method)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at android.os.Handler.handleCallback(Handler.java:739)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at android.os.Handler.dispatchMessage(Handler.java:95)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at android.os.Looper.loop(Looper.java:148)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
12-27 00:26:08.556 31439 32503 E unknown:ReactNative: at java.lang.Thread.run(Thread.java:818)
Here is the screenshot from the app
Will appreciate your help!
Which option is actually causing the error? source or format?
Any of the option throws this error. I tried them both together and individually as well
The error is thrown when the library tries to read the recorded file, to get the duration.
Since you said the output file is corrupted, I think that's why the error is thrown.
Now the problem gets to why the recorder can't produce the correct file.
I suggest debugging by making sure the parameters passed to the Media Recorder are valid e.g. setOutputFormat()
Let me check that.
Will SoundRecorder.VOICE_CALL
require additional permissions?
I'm not sure. Btw I think it should be SoundRecorder.SOURCE_VOICE_CALL
Oops! That's right. Will change it and re-check. Thanks!
Okay. I think I figured it out. There is a problem with SoundRecorder.SOURCE_VOICE_CALL
This source does not work with all devices. Some manufacturers disable this and can't be used.
Ref: https://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html#VOICE_CALL
Closing this issue for now. Thanks!
This fix occurs on stop:
Try to put this
try {
retriever.setDataSource(mOutput);
} catch (Exception e) {
promise.reject("stopping_failed" , "Stop failed " + e);
return;
}
This catch the error and solve the issue!