Cordova Media Capture Android error no.3 issue - android

I am currently developing a mobile application that is all about very short sound recordings and for the time sake I decided to build it with Cordova (not Phonegap). Unfortunately today I have been fighting with the actual sound recording on my Nexus 5.
I am using the Cordova media-capture plugin, The code currently running is exactly the code from their documentation.
On older device, everything runs great. On my Nexus 5 though, when I click on button to record audio, it just returns error code number 3 (No media files recorded) even without opening the audio recorder. I thought it might be problem with new Android, but on simulator it runs fine. I also thought that somehow it could be connected to that I cannot find any audio recording app on my device, so I installed one and still nothing.
Then I thought maybe I am doing something wrong, so I installed this app: https://github.com/Icenium/sample-capture and the same problem.
There has been some advice around here to update the Capture Java file, which I did and still didn't help. What can I try next?

This is because there is no application installed, by default, to handle the intent (as explained above by others).
Try installing an application that handles that intent. For example I used this one:
https://play.google.com/store/apps/details?id=com.brightattic.soundrecorder&hl=en
(Please note I offer no endorsement of the app other than it worked to prove that the problem was a lack of sound recorder app).

Maybe try to set the targetsdk to 18 instead of 19 in androidmanifest.xml (and of course be sure to have installed api 18 in android sdk manager).
This should force the new kitkat chrome webview to operate in quirk mode and behave like the webview in jellybean.

I had the same issue, running adb logcat is useful:
W/System.err(22102): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.provider.MediaStore.RECORD_SOUND }
...
D/CordovaLog(22102): file:///android_asset/www/js/index.js: Line 77 : Capture ERROR: {"message":"Canceled.","code":3}
For me the problem is that Nexus 5 (android 4.4.2) doesn't handle the Intent, i.e. doesn't seem to have a default audio recorder.
On devices which do have a default audio recorder, you might see this error if that application doesn't include a receiver for RECORD_SOUND..

Related

Recorded Audio using MediaRecorder.AudioSource.VOICE_COMMUNICATION is empty on some devices with Android 10

I am recording audio for voice messages in the app using the following code.
MediaRecorder audioRecorder = new MediaRecorder();
audioRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.HE_AAC);
audioRecorder.setOutputFile(audioRecordingFile);
audioRecorder.prepare();
audioRecorder.start();
Use of MediaRecorder.AudioSource.VOICE_COMMUNICATION instead of MediaRecorder.AudioSource.MIC) is very helpful in recording pre-processed clean audios.
But, recently I found some issues in which the recorded files are empty are being reported on a few devices which were recently updated to Android 10. It should be noted that not all Android 10 devices have these issues, only a few i.e Nokia 6.1 and Mi A2.
There is no error or exception but just empty audio output files.
If I use MediaRecorder.AudioSource.MIC) then the issue is not seen.
I found the following information related to Android 10 and VOICE_COMMUNICATION
The Android 10 release includes the following requirements for capture with VOICE_COMMUNICATION.
Based on this I checked the availability of AcousticEchoCanceler,AutomaticGainControl and NoiseSuppressor using the following code.
AcousticEchoCanceler.isAvailable()
AutomaticGainControl.isAvailable()
NoiseSuppressor.isAvailable()
And found the same result on Mi A2 and OnePlus 6 with Android 10. Both of the devices show AcousticEchoCanceler and NoiseSuppressor as available and AutomaticGainControl as not available.
Since the issue is not present on all Android devices, I don`t want to fall back on using MediaRecorder.AudioSource.MIC). At the same time, there is no error, exception or differentiating factor which tells me when to fall back on MediaRecorder.AudioSource.MIC).
UPDATE: The issue gets resolved when Google Assistant is turned off on Mi A2.
This might be the pointer : https://developer.android.com/guide/topics/media/sharing-audio-input
Any help regarding this is appreciated.
I ended up using MediaRecorder.AudioSource.VOICE_RECOGNITION instead of MediaRecorder.AudioSource.VOICE_COMMUNICATION on all android versions.
We ended up taking samples on 15+ different devices and found out that MediaRecorder.AudioSource.VOICE_RECOGNITION works best with the majority devices including high-end and mid-range phones.
As per my understanding, the original issue faced on few devices on some devices seems like implementation issues by the OEMs with respect to Android 10 and VOICE_COMMUNICATION https://source.android.com/devices/audio/implement-pre-processing

Can an Android app modify the audio system of the device?

I've received a bug report from an user of my app. She said that after downloaded my app and used it, the speaker of the mobile phone didn't emit any sound anymore, even after deleting the app. She solved the problem only after restarting the device in safe mode.
Is it really possible that my app caused this? Have you heard about similar cases?
The app is an audio player for an audio codec not supported by Android versions previous to 5.0.
I've used the AudioTrack class for playing the audio and a custom decoder made with the Java Native Interface and a third part library written in C.
The device is a Galaxy A3 (2017) with Android 7.0.
I've updated the app some months ago, substituting the old deprecated AudioTrack constructor with the new one that make use of the AudioTrack.Builder. I haven't received new similar report, so maybe the problem is solved.

cordova no sound on bluetooth speakers

I am working on an android (and IOS) application, the application plays audio messages without problem. My problem is as follow:
if the mobile is already connected to bluetooth (bluetooth enabled and connected), if then I launch my application and I play an audio file in this case I hear nothing neither on the telephine nor on the bluetooth speaker.
But, if I launch my application and then I activate the bluetooth,then play the audio file, there is no problem, the sound goes out well on my bluetooth speakers.
The solution I used for now is that when I launch my application I disable completely the bluetooth and then I restart it on the onDeviceready (using a plugin cordova) it works fin like that but it is not ideal as solution, it is very annoying for the users that the bluetooth disconnect and reconnect especially when it is the bluetooth of the car.
Does anyone have the same problem and can you help me find another solution.
I use the latest versions of Cordova (7.0.1), android (6.2.3) ...
and I use the plugova cordova-plugin-bluetoothle to restart bluetooth (disable then enable after the launch of the application)
Any Idea please?
Exact same problem here! I'm working on a musical webapp for Android (6.4.0) and iOS (4.5.3) built with Cordova (7.1.0). I use the webaudio API to play sounds. Everything works great on every platforms except in this specific case:
If the bluetooth is enabled and connected before I launch my App there is no sounds at all playing. This problem occurs only on Android. On some model/type of Android devices it works, on some others it doesn't... Example:
Samsung J3 (Android v5.1.1) = no sounds playing
LENOVO TB2 (Android v5.1.1) = no sounds playing
HUAWEI VTR (Android v7.0) = no sounds playing
LG G6 (Android v7.0) = it works like a charm!
Unfortunately I didn't find any 'clean' solutions yet. I do the same than yours (BT=bluetooth):
force to disable BT if this one is connected,
reload the entire page,
re-connect the BT.
The only hint I found during my tests is about an attribute into the AudioContext object. The AudioContext object has a attribute called baseLatency. The official DOC isn't really clear about it:
This represents the number of seconds of processing latency incurred by the AudioContext passing the audio from the AudioDestinationNode to the audio subsystem [...]
What I understood is that this property give you an estimation (in seconds) of the time/delay needed by AudioContext to bring a sound to his destination...
Right after the AudioContext has been initialized in your code, you can ask for this baseLatency (read-only property):
var context = new AudioContext();
console.log(context.baseLatency);// 0.008 for example
What I noticed during my tests, is that this baseLatency is always higher than 0.2 everytime the problem occurs.
Example with bluetooth DISabled:
// baseLatency on computer = 0.008
// baseLatency on iOS devices = 0.05
// baseLatency on Android devices = 0.05
Example with bluetooth ENabled:
// baseLatency on computer = 0.008 (same)
// baseLatency on iOS devices = 0.05 (same)
// baseLatency on (some) Android devices = 0.2 (HIGHER)
Well, I did this test hundreds times, each times the same result. If BT is enabled before you launch the App on some Androids devices, the baseLatency will be higher than 0.2 meaning the AudioContext won't be able to play any sounds in your app. This is not a solution I know, but that can helps a little by letting you know for sure if the App will play sounds or not.
I tried to re-initialize the AudioContext object, but this doesn't works at all... the baseLatency stay the same even if you reconstruct the AudioContext object.
I hope this tiny hint could help us to find a solution!

Cordova sound bug on android

i made a simple android app with cordova to play audio whenever a button is clicked. it works on my huawei phone (android 5.1.1) and the google emulator, but it does NOT work on any other android phones (android 4.x [4.1;4.2;4.4]).
i have the media plugin installed into the project, haven't done any android-version specific restrictions
index.js: http://puu.sh/mrY3g/9d4a99d3e9.txt
config.xml: http://puu.sh/mrY7a/ae9b06aa51.txt
thanks a lot
ps. if u need more files for investigation/troubleshooting, leave a comment :)
EDIT
It was something with Content Security Policy, fixed that, but now when i logcat my phone, when i try to play the .mp3 file, it says Permission Denied. This happens ONLY on android 4.x (On browser and android 5 works perfectly). Any help is appreciated.
I changed the way sound is played from onclick(function a) where in a() was made an audio/media control (backend) which played the sound. now i made an <audio> control in the html and via javascript i play it

Using audio recorder at android simulator

I want to use an audio capture feature at my app. I followed this link at developer.android.com.
I'm using Android Studio 1.4 and a Nexus 5 with Api21 as virtual device. At developer.android it is descripted that it's not possible to use the audio capture feature with an simulator:
Note: The Android Emulator does not have the ability to capture audio, but actual devices are likely to provide these capabilities.
But is this an information that is up to date? I'm able to use the record button but the activity crashes after pressing stop. I can see the audiorecordtest.3gp file on the simulated device and if I save it to my computer I can play my recorded audio. The crash comes without any shown exception. If I ask for
context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE);
I got back a true. It seems like the simulator is able to capture audio but can't handle correctly the stopping of it? Is there a way to get around?
One aspect of Tamper Checking involves testing for an Emulator running your app...
In THIS article (Paragraph 4.1), Emulator detection is described... The tests detect many emulators, but throw some "false positives", depending on the device.
False positives render some emulator test's, described in the article, not appropriate for production, but are fine in a test environment where you know your devices and their test responses.

Categories

Resources